protected override void ExecuteImpl()
        {
            var parameters   = new Dictionary <string, object>();
            var sqlStatement = CreateSqlStatement(parameters);

            using (var scope = SuppressExistingTransactionScope ? new TransactionScope(TransactionScopeOption.Suppress) : null)
            {
                var connection = EtlConnectionManager.GetConnection(ConnectionString, this);
                try
                {
                    lock (connection.Lock)
                    {
                        using (var cmd = connection.Connection.CreateCommand())
                        {
                            cmd.CommandTimeout = CommandTimeout;
                            cmd.CommandText    = sqlStatement;
                            cmd.FillCommandParameters(parameters);

                            var transactionId = Transaction.Current.ToIdentifierString();
                            RunCommand(cmd, transactionId, parameters);
                        }
                    }
                }
                finally
                {
                    EtlConnectionManager.ReleaseConnection(this, ref connection);
                }
            }
        }
        public void GetConnection(AbstractAdoNetDbReader process, out DatabaseConnection connection, out IDbTransaction transaction)
        {
            if (!_readerConnections.TryGetValue(process.ConnectionString.Name, out var t))
            {
                var conn = EtlConnectionManager.GetNewConnection(process.ConnectionString, process);
                var tran = conn.Connection.BeginTransaction();
                t = new Tuple <DatabaseConnection, IDbTransaction>(conn, tran);
                _readerConnections.Add(process.ConnectionString.Name, t);
            }

            connection  = t.Item1;
            transaction = t.Item2;
        }
示例#3
0
        protected override void ExecuteImpl()
        {
            using (var scope = SuppressExistingTransactionScope ? new TransactionScope(TransactionScopeOption.Suppress) : null)
            {
                var connection = EtlConnectionManager.GetConnection(ConnectionString, this);
                try
                {
                    lock (connection.Lock)
                    {
                        var transactionId = Transaction.Current.ToIdentifierString();

                        // todo: support returning parameters
                        var sqlStatements = CreateSqlStatements(ConnectionString, connection.Connection, transactionId);
                        if (sqlStatements.Count > 0)
                        {
                            using (var cmd = connection.Connection.CreateCommand())
                            {
                                cmd.CommandTimeout = CommandTimeout;

                                var startedOn = Stopwatch.StartNew();

                                for (var i = 0; i < sqlStatements.Count; i++)
                                {
                                    var sqlStatement = sqlStatements[i];

                                    cmd.CommandText = sqlStatement;
                                    try
                                    {
                                        startedOn.Restart();
                                        RunCommand(cmd, i, startedOn, transactionId);
                                    }
                                    catch (Exception)
                                    {
                                        LogSucceeded(i - 1, transactionId);
                                        throw;
                                    }
                                }

                                LogSucceeded(sqlStatements.Count - 1, transactionId);
                            }
                        }
                    }
                }
                finally
                {
                    EtlConnectionManager.ReleaseConnection(this, ref connection);
                }
            }
        }