@@ -32,18 +32,12 @@ public sealed class DbHelper : IDisposable
3232 private readonly string _connectionString ;
3333 private DbConnection _connection ;
3434 private readonly bool _ownsConnection ;
35- private readonly Internal . DataAccessProviderType _providerType ;
3635 private readonly IRepositoryConventions _conventions ;
3736
3837 #endregion
3938
4039 #region Properties
4140
42- /// <summary>
43- /// Gets the provider type.
44- /// </summary>
45- internal Internal . DataAccessProviderType ProviderType { get { return _providerType ; } }
46-
4741 /// <summary>
4842 /// Gets the provider factory.
4943 /// </summary>
@@ -88,13 +82,14 @@ internal DbHelper(IRepositoryConventions conventions, string nameOrConnectionStr
8882 Guard . NotNull ( conventions , nameof ( conventions ) ) ;
8983 Guard . NotEmpty ( nameOrConnectionString , nameof ( nameOrConnectionString ) ) ;
9084
91- var css = GetConnectionStringSettings ( nameOrConnectionString ) ;
85+ var css = Guard . EnsureNotNull (
86+ GetConnectionStringSettings ( nameOrConnectionString ) ,
87+ "The connection string does not exist in your configuration file." ) ;
9288
9389 _conventions = conventions ;
9490 _factory = Internal . DbProviderFactories . GetFactory ( css . ProviderName ) ;
9591 _connectionString = css . ConnectionString ;
9692 _ownsConnection = true ;
97- _providerType = Internal . DataAccessProvider . GetProviderType ( css . ProviderName ) ;
9893 }
9994
10095 /// <summary>
@@ -113,7 +108,6 @@ internal DbHelper(IRepositoryConventions conventions, string providerName, strin
113108 _factory = Internal . DbProviderFactories . GetFactory ( providerName ) ;
114109 _connectionString = connectionString ;
115110 _ownsConnection = true ;
116- _providerType = Internal . DataAccessProvider . GetProviderType ( providerName ) ;
117111 }
118112
119113 /// <summary>
@@ -126,16 +120,9 @@ internal DbHelper(IRepositoryConventions conventions, DbConnection existingConne
126120 Guard . NotNull ( conventions , nameof ( conventions ) ) ;
127121 Guard . NotNull ( existingConnection , nameof ( existingConnection ) ) ;
128122
129- if ( existingConnection . State == ConnectionState . Closed )
130- existingConnection . Open ( ) ;
131-
132123 _conventions = conventions ;
133124 _connection = existingConnection ;
134125 _ownsConnection = false ;
135-
136- var css = GetConnectionStringSettings ( existingConnection . ConnectionString ) ;
137-
138- _providerType = Internal . DataAccessProvider . GetProviderType ( css . ProviderName ) ;
139126 }
140127
141128 #endregion
@@ -1305,21 +1292,18 @@ private static ConnectionStringSettings GetConnectionStringSettings(string nameO
13051292 {
13061293 var css = ConfigurationManager . ConnectionStrings [ nameOrConnectionString ] ;
13071294
1308- if ( css == null )
1295+ if ( css != null )
1296+ return css ;
1297+
1298+ for ( var i = 0 ; i < ConfigurationManager . ConnectionStrings . Count ; i ++ )
13091299 {
1310- for ( var i = 0 ; i < ConfigurationManager . ConnectionStrings . Count ; i ++ )
1311- {
1312- css = ConfigurationManager . ConnectionStrings [ i ] ;
1300+ css = ConfigurationManager . ConnectionStrings [ i ] ;
13131301
1314- if ( css . ConnectionString . Equals ( nameOrConnectionString ) )
1315- break ;
1316- }
1302+ if ( css . ConnectionString . Equals ( nameOrConnectionString ) )
1303+ return css ;
13171304 }
13181305
1319- if ( css == null )
1320- throw new ArgumentException ( "The connection string does not exist in your configuration file." ) ;
1321-
1322- return css ;
1306+ return null ;
13231307 }
13241308
13251309 private static T ConvertValue < T > ( object value )
0 commit comments