12using System.Data.SqlClient;
14using Microsoft.Data.SqlClient;
34 [Obsolete(
"Use dependency injection instead",
false)]
37 private static readonly
object _lock =
new object();
38 private readonly
string _connectionString;
39 private readonly
string _label;
82 return GetManager(database, isDatabaseName,
"default");
104 var connection = ConfigurationManager.ConnectionStrings[database];
105 if (connection ==
null)
108 var conn = ConfigurationManager.ConnectionStrings[database].ConnectionString;
109 if (
string.IsNullOrEmpty(conn))
115 var ctxName = GetContextName(database, label);
118 var cached = ApplicationContext.LocalContext.GetValueOrNull(ctxName);
131 ApplicationContext.LocalContext[ctxName] = mgr;
141 _connectionString = connectionString;
143 Connection =
new SqlConnection(connectionString);
147 private static string GetContextName(
string connectionString,
string label)
149 return "__db:" + label +
"-" + connectionString;
165 private void AddRef()
178 ApplicationContext.LocalContext.Remove(GetContextName(_connectionString, _label));
190 GC.SuppressFinalize(
this);
Exception thrown due to configuration errors.
Provides an automated way to reuse open database connections within the context of a single data port...
static ConnectionManager GetManager(string database, bool isDatabaseName, string label)
Gets the ConnectionManager object for the specified database.
static ConnectionManager GetManager(string database, bool isDatabaseName)
Gets the ConnectionManager object for the specified database.
static ConnectionManager GetManager(string database)
Gets the ConnectionManager object for the specified database.
static ConnectionManager GetManager(string database, string label)
Gets the ConnectionManager object for the specified database.
int RefCount
Gets the current reference count for this object.
void Dispose()
Dispose object, dereferencing or disposing the connection it is managing.
IDbConnection Connection
Dispose object, dereferencing or disposing the connection it is managing.
virtual void Dispose(bool p)
Dispose object, dereferencing or disposing the context it is managing.
A strongly-typed resource class, for looking up localized strings, etc.
static string DatabaseNameNotFound
Looks up a localized string similar to Database name not found in config file ({0}).