@@ -58,8 +58,9 @@ public Connection(IConfiguration configuration, DbProviderFactory factory, strin
5858 Name = string . IsNullOrEmpty ( name ) ? "Default" : name ;
5959 Factory = factory ?? SqlClientFactory . Instance ;
6060 ConnectionString = ! string . IsNullOrEmpty ( connection ) ? connection : ( configuration . GetConnectionString ( Name ) ?? Name ) ;
61- if ( Factory is SqlClientFactory )
62- DatabaseName = DatabaseNameRegex . Match ( ConnectionString ) . Groups [ 1 ] . Value ;
61+ var DatabaseRegexResult = DatabaseNameRegex . Match ( ConnectionString ) ;
62+ if ( DatabaseRegexResult . Success )
63+ DatabaseName = DatabaseRegexResult . Groups [ "name" ] . Value ;
6364 ParameterPrefix = ! string . IsNullOrEmpty ( parameterPrefix ) ? parameterPrefix : GetParameterPrefix ( Factory ) ;
6465 CommandTimeout = GetCommandTimeout ( ConnectionString ) ;
6566 }
@@ -115,7 +116,7 @@ public Connection(IConfiguration configuration, DbProviderFactory factory, strin
115116 /// Gets the database.
116117 /// </summary>
117118 /// <value>The database.</value>
118- private static Regex DatabaseNameRegex { get ; } = new Regex ( "Initial Catalog=( [^;]*)" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
119+ private static Regex DatabaseNameRegex { get ; } = new Regex ( "( Initial Catalog|Database|Data Source)=(?<name> [^;]*)" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
119120
120121 /// <summary>
121122 /// Gets the command timeout.
@@ -140,12 +141,7 @@ private static int GetCommandTimeout(string connectionString)
140141 private static string GetParameterPrefix ( DbProviderFactory factory )
141142 {
142143 var SourceType = factory . GetType ( ) . FullName ?? string . Empty ;
143- if ( SourceType . Contains ( "MySql" , StringComparison . OrdinalIgnoreCase ) )
144- return "?" ;
145- else if ( SourceType . Contains ( "Oracle" , StringComparison . OrdinalIgnoreCase ) )
146- return ":" ;
147- else
148- return "@" ;
144+ return SourceType . Contains ( "Oracle" , StringComparison . OrdinalIgnoreCase ) ? ":" : "@" ;
149145 }
150146 }
151147}
0 commit comments