34 private static object _lock =
new object();
35 private C _connection;
36 private string _connectionString;
37 private string _label;
80 return GetManager(database, isDatabaseName,
"default");
102#if NETSTANDARD2_0 || NET5_0
103 throw new NotSupportedException(
"isDatabaseName==true");
105 var connection = ConfigurationManager.ConnectionStrings[database];
106 if (connection ==
null)
109 var conn = ConfigurationManager.ConnectionStrings[database].ConnectionString;
110 if (
string.IsNullOrEmpty(conn))
117 var ctxName = GetContextName(database, label);
120 var cached = ApplicationContext.LocalContext.GetValueOrNull(ctxName);
133 ApplicationContext.LocalContext[ctxName] = mgr;
143 _connectionString = connectionString;
146 _connection =
new C { ConnectionString = connectionString };
150 private static string GetContextName(
string connectionString,
string label)
152 return "__db:" + label +
"-" + connectionString;
166 private int _refCount;
174 get {
return _refCount; }
177 private void AddRef()
188 _connection.Dispose();
190 ApplicationContext.LocalContext.Remove(GetContextName(_connectionString, _label));
Provides an automated way to reuse open database connections within the context of a single data port...
void Dispose()
Dispose object, dereferencing or disposing the connection it is managing.
static ConnectionManager< C > GetManager(string database, string label)
Gets the ConnectionManager object for the specified database.
static ConnectionManager GetManager(string database)
Gets the ConnectionManager object for the specified database.
int RefCount
Gets the current reference count for this object.
static ConnectionManager< C > GetManager(string database, bool isDatabaseName)
Gets the ConnectionManager object for the specified database.
static ConnectionManager< C > GetManager(string database)
Gets the ConnectionManager object for the specified database.
IDbConnection Connection
Dispose object, dereferencing or disposing the connection it is managing.
static ConnectionManager< C > GetManager(string database, bool isDatabaseName, string label)
Gets the ConnectionManager object for the specified database.
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}).