File tree Expand file tree Collapse file tree 2 files changed +38
-10
lines changed Expand file tree Collapse file tree 2 files changed +38
-10
lines changed Original file line number Diff line number Diff line change @@ -540,5 +540,40 @@ private static IObjectsFactory CreateCustomObjectsFactory(string assemblyQualifi
540540 }
541541 }
542542
543+
544+ /// <summary>
545+ /// Get a named connection string, if configured.
546+ /// </summary>
547+ /// <exception cref="HibernateException">
548+ /// Thrown when a <see cref="ConnectionStringName"/> was found
549+ /// in the <c>settings</c> parameter but could not be found in the app.config.
550+ /// </exception>
551+ internal static string GetNamedConnectionString ( IDictionary < string , string > settings )
552+ {
553+ string connStringName ;
554+ if ( ! settings . TryGetValue ( ConnectionStringName , out connStringName ) )
555+ return null ;
556+
557+ ConnectionStringSettings connectionStringSettings = ConfigurationManager . ConnectionStrings [ connStringName ] ;
558+ if ( connectionStringSettings == null )
559+ throw new HibernateException ( $ "Could not find named connection string '{ connStringName } '.") ;
560+
561+ return connectionStringSettings . ConnectionString ;
562+ }
563+
564+
565+ /// <summary>
566+ /// Get the configured connection string, from <see cref="ConnectionString"/> if that
567+ /// is set, otherwise from <see cref="ConnectionStringName"/>, or null if that isn't
568+ /// set either.
569+ /// </summary>
570+ internal static string GetConfiguredConnectionString ( IDictionary < string , string > settings )
571+ {
572+ // Connection string in the configuration overrides named connection string.
573+ if ( ! settings . TryGetValue ( ConnectionString , out string connString ) )
574+ connString = GetNamedConnectionString ( settings ) ;
575+
576+ return connString ;
577+ }
543578 }
544579}
Original file line number Diff line number Diff line change @@ -65,22 +65,15 @@ public virtual void Configure(IDictionary<string, string> settings)
6565 }
6666
6767 /// <summary>
68- /// Get the .NET 2.0 named connection string
68+ /// Get a named connection string, if configured.
6969 /// </summary>
7070 /// <exception cref="HibernateException">
7171 /// Thrown when a <see cref="Environment.ConnectionStringName"/> was found
72- /// in the <c>settings</c> parameter but could not be found in the app.config
72+ /// in the <c>settings</c> parameter but could not be found in the app.config.
7373 /// </exception>
7474 protected virtual string GetNamedConnectionString ( IDictionary < string , string > settings )
7575 {
76- string connStringName ;
77- if ( ! settings . TryGetValue ( Environment . ConnectionStringName , out connStringName ) )
78- return null ;
79-
80- ConnectionStringSettings connectionStringSettings = ConfigurationManager . ConnectionStrings [ connStringName ] ;
81- if ( connectionStringSettings == null )
82- throw new HibernateException ( string . Format ( "Could not find named connection string {0}" , connStringName ) ) ;
83- return connectionStringSettings . ConnectionString ;
76+ return Environment . GetNamedConnectionString ( settings ) ;
8477 }
8578
8679 /// <summary>
You can’t perform that action at this time.
0 commit comments