Ejemplo n.º 1
0
        private async Task PrepareAsync(CancellationToken cancellationToken)
        {
            Session.EnsureNotDisposed();
            await driver.OpenConnectionAsync(Session, connection, cancellationToken).ConfigureAwait(false);

            try {
                foreach (var initializationSqlScript in initializationSqlScripts)
                {
                    using (var command = connection.CreateCommand(initializationSqlScript))
                        await driver.ExecuteNonQueryAsync(Session, command, cancellationToken).ConfigureAwait(false);
                }
            }
            catch (OperationCanceledException) {
                connection.Close();
                throw;
            }

            if (pendingTransaction == null)
            {
                return;
            }
            var transaction = pendingTransaction;

            pendingTransaction = null;
            if (connection.ActiveTransaction == null) // Handle external transactions
            {
                driver.BeginTransaction(Session, connection, IsolationLevelConverter.Convert(transaction.IsolationLevel));
            }
        }
        private void Prepare()
        {
            Session.EnsureNotDisposed();
            driver.EnsureConnectionIsOpen(Session, connection);
            foreach (var script in initializationSqlScripts)
            {
                using (var command = connection.CreateCommand(script)) {
                    driver.ExecuteNonQuery(Session, command);
                }
            }

            initializationSqlScripts.Clear();
            if (pendingTransaction == null)
            {
                return;
            }

            var transaction = pendingTransaction;

            pendingTransaction = null;
            if (connection.ActiveTransaction == null)
            {
                // Handle external transactions
                driver.BeginTransaction(Session, connection, IsolationLevelConverter.Convert(transaction.IsolationLevel));
            }
        }
        public void BeginTransaction(Session session, SqlConnection connection, IsolationLevel?isolationLevel)
        {
            if (isLoggingEnabled)
            {
                SqlLog.Info(Strings.LogSessionXBeginningTransactionWithYIsolationLevel, session.ToStringSafely(),
                            isolationLevel);
            }

            isolationLevel ??= IsolationLevelConverter.Convert(GetConfiguration(session).DefaultIsolationLevel);

            try {
                connection.BeginTransaction(isolationLevel.Value);
            }
            catch (Exception exception) {
                throw ExceptionBuilder.BuildException(exception);
            }
        }
        public async ValueTask BeginTransactionAsync(
            Session session, SqlConnection connection, IsolationLevel?isolationLevel, CancellationToken token = default)
        {
            if (isLoggingEnabled)
            {
                SqlLog.Info(Strings.LogSessionXBeginningTransactionWithYIsolationLevel, session.ToStringSafely(),
                            isolationLevel);
            }

            isolationLevel ??= IsolationLevelConverter.Convert(GetConfiguration(session).DefaultIsolationLevel);

            try {
                await connection.BeginTransactionAsync(isolationLevel.Value, token).ConfigureAwait(false);
            }
            catch (Exception exception) {
                throw ExceptionBuilder.BuildException(exception);
            }
        }