1#if !NETSTANDARD2_0 && !NET5_0 && !NET6_0
12using System.Data.Common;
31 [Obsolete(
"Use dependency injection",
false)]
32 public class ConnectionManager : IDisposable, Core.IUseApplicationContext
34 private static object _lock =
new object();
35 private IDbConnection _connection;
36 private string _connectionString;
37 private string _label;
39 private ApplicationContext ApplicationContext {
get;
set; }
40 ApplicationContext Core.IUseApplicationContext.ApplicationContext {
get => ApplicationContext;
set => ApplicationContext = value; }
83 return GetManager(database, isDatabaseName,
"default");
105 var connection = ConfigurationManager.ConnectionStrings[database];
106 if (connection ==
null)
109 var conn = ConfigurationManager.ConnectionStrings[database].ConnectionString;
110 if (
string.IsNullOrEmpty(conn))
116 var ctxName = GetContextName(database, label);
139#if !NETSTANDARD2_0 && !NET5_0 && !NET6_0
140 internal static string DbProvider {
get;
set; } =
"System.Data.SqlClient";
143 private ConnectionManager(
string connectionString,
string label)
146 _connectionString = connectionString;
148#if NETSTANDARD2_0 || NET5_0 || NET6_0
149 _connection =
new System.Data.SqlClient.SqlConnection(connectionString);
153 DbProviderFactory factory = DbProviderFactories.GetFactory(DbProvider);
156 _connection = factory.CreateConnection();
157 _connection.ConnectionString = connectionString;
162 private static string GetContextName(
string connectionString,
string label)
164 return "__db:" + label +
"-" + connectionString;
180 private int _refCount;
188 get {
return _refCount; }
191 private void AddRef()
202 _connection.Dispose();
Provides consistent context information between the client and server DataPortal objects.
ContextDictionary LocalContext
Returns the application-specific context data that is local to the current AppDomain.
Exception thrown due to configuration errors.
Provides an automated way to reuse open database connections within the context of a single data port...
ConnectionManager GetManager(string database, bool isDatabaseName, string label)
Gets the ConnectionManager object for the specified database.
void Dispose()
Dispose object, dereferencing or disposing the connection it is managing.
ConnectionManager GetManager(string database, bool isDatabaseName)
Gets the ConnectionManager object for the specified database.
ConnectionManager GetManager(string database, string label)
Gets the ConnectionManager object for the specified database.
ConnectionManager GetManager(string database)
Gets the ConnectionManager object for the specified database.
int RefCount
Gets the current reference count for this object.
IDbConnection Connection
Dispose object, dereferencing or disposing the connection 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}).