/// <summary> /// Creates a new transaction/savepoint wrapper class /// </summary> /// <param name="connection">Database connection, null if it's a dummy wrapper (nested transaction without creating a savepoint)</param> /// <param name="savepointName">Savepoint name, null if it's a transaction instead of a savepoint</param> internal DBSqlServerTransaction(DBSqlServerConnectionInstance connection, string savepointName) { if ((connection is null) && (!(savepointName is null))) { throw new ArgumentNullException(nameof(connection)); } Connection = connection; SavepointName = savepointName; }
/// <summary> /// Creates a disposable container with a database connection, creating a new connection if necessary /// </summary> /// <param name="connection">Database connection (null for a new connection)</param> /// <param name="connectionStringName">Connection string name (must not be null if connection is null)</param> public static DBSqlServerConnection Create(DBSqlServerConnection connection, string connectionStringName) { var newConnection = new DBSqlServerConnection(); if (connection is null) { newConnection.DisposeConnection = true; newConnection.Connection = DBSqlServerConnectionInstance.Open(connectionStringName); } else { newConnection.DisposeConnection = false; newConnection.Connection = connection.Connection; } return(newConnection); }
/// <summary> /// Creates a disposable container with a database connection, creating a new connection if necessary /// </summary> /// <param name="connection">Database connection (null for a new connection)</param> /// <param name="connectionStringName">Connection string name (must not be null if connection is null)</param> protected static T Create <T>(DBSqlServerConnection connection, string connectionStringName) where T : DBSqlServerConnection { var newConnection = (T)Activator.CreateInstance(type: typeof(T), nonPublic: true); if (connection is null) { newConnection.DisposeConnection = true; newConnection.Connection = DBSqlServerConnectionInstance.Open(connectionStringName); } else { newConnection.DisposeConnection = false; newConnection.Connection = connection.Connection; } return(newConnection); }
/// <summary> /// Creates a disposable container with a database connection, creating a new connection if necessary /// </summary> /// <param name="connection">Database connection (null for a new connection)</param> /// <param name="connectionStringName">Connection string name (must not be null if connection is null)</param> public static async Task <DBSqlServerConnection> CreateAsync(DBSqlServerConnection connection, string connectionStringName) { var newConnection = new DBSqlServerConnection(); if (connection is null) { newConnection.DisposeConnection = true; newConnection.Connection = await DBSqlServerConnectionInstance.OpenAsync(connectionStringName).ConfigureAwait(false); } else { newConnection.DisposeConnection = false; newConnection.Connection = connection.Connection; } return(newConnection); }
/// <summary> /// Creates a disposable container with a database connection, creating a new connection if necessary /// </summary> /// <param name="connection">Database connection (null for a new connection)</param> /// <param name="connectionStringName">Connection string name (must not be null if connection is null)</param> protected static async Task <T> CreateAsync <T>(DBSqlServerConnection connection, string connectionStringName) where T : DBSqlServerConnection { var newConnection = (T)Activator.CreateInstance(type: typeof(T), nonPublic: true); if (connection is null) { newConnection.DisposeConnection = true; newConnection.Connection = await DBSqlServerConnectionInstance.OpenAsync(connectionStringName).ConfigureAwait(false); } else { newConnection.DisposeConnection = false; newConnection.Connection = connection.Connection; } return(newConnection); }