public SqlConnectionWrapperFactory(SqlServerDataStoreConfiguration configuration, SqlTransactionHandler sqlTransactionHandler)
        {
            EnsureArg.IsNotNull(configuration, nameof(configuration));
            EnsureArg.IsNotNull(sqlTransactionHandler, nameof(sqlTransactionHandler));

            _configuration         = configuration;
            _sqlTransactionHandler = sqlTransactionHandler;
        }
Пример #2
0
        public SqlConnectionWrapper(SqlServerDataStoreConfiguration configuration, SqlTransactionHandler sqlTransactionHandler, bool enlistInTransactionIfPresent)
        {
            EnsureArg.IsNotNull(configuration, nameof(configuration));
            EnsureArg.IsNotNull(sqlTransactionHandler, nameof(sqlTransactionHandler));

            _sqlTransactionHandler        = sqlTransactionHandler;
            _enlistInTransactionIfPresent = enlistInTransactionIfPresent;

            if (_enlistInTransactionIfPresent && sqlTransactionHandler.SqlTransactionScope?.SqlConnection != null)
            {
                SqlConnection = sqlTransactionHandler.SqlTransactionScope.SqlConnection;
            }
            else
            {
                SqlConnection = new SqlConnection(configuration.ConnectionString);
            }

            if (_enlistInTransactionIfPresent && sqlTransactionHandler.SqlTransactionScope != null && sqlTransactionHandler.SqlTransactionScope.SqlConnection == null)
            {
                sqlTransactionHandler.SqlTransactionScope.SqlConnection = SqlConnection;
            }

            if (SqlConnection.State != ConnectionState.Open)
            {
                SqlConnection.Open();
            }

            if (enlistInTransactionIfPresent && sqlTransactionHandler.SqlTransactionScope != null)
            {
                SqlTransaction = sqlTransactionHandler.SqlTransactionScope.SqlTransaction ?? SqlConnection.BeginTransaction();

                if (sqlTransactionHandler.SqlTransactionScope.SqlTransaction == null)
                {
                    sqlTransactionHandler.SqlTransactionScope.SqlTransaction = SqlTransaction;
                }
            }
        }
        public SqlTransactionScope(SqlTransactionHandler sqlTransactionHandler)
        {
            EnsureArg.IsNotNull(sqlTransactionHandler, nameof(SqlTransactionHandler));

            _sqlTransactionHandler = sqlTransactionHandler;
        }