Esempio n. 1
0
        public virtual bool Exists()
        {
            var exists = false;

            if (!_creator.Exists())
            {
                return(exists);
            }

            var command = (SqlCommand)_connection.DbConnection.CreateCommand();

            command.CommandText =
                @"SELECT 1 FROM [INFORMATION_SCHEMA].[TABLES]
WHERE [TABLE_SCHEMA] = N'dbo' AND [TABLE_NAME] = '__MigrationHistory' AND [TABLE_TYPE] = 'BASE TABLE'";

            _connection.Open();
            try
            {
                exists = command.ExecuteScalar() != null;
            }
            finally
            {
                _connection.Close();
            }

            return(exists);
        }
Esempio n. 2
0
        public virtual bool Exists()
        {
            var exists = false;

            if (!_creator.Exists())
            {
                return(exists);
            }

            var command = (SqlCommand)_connection.DbConnection.CreateCommand();

            command.CommandText = "SELECT OBJECT_ID(N'dbo." + MigrationHistoryTableName + "');";

            _connection.Open();
            try
            {
                exists = command.ExecuteScalar() != DBNull.Value;
            }
            finally
            {
                _connection.Close();
            }

            return(exists);
        }
        private bool Exists(bool retryOnNotExists)
        {
            var retryCount = 0;
            var giveUp     = DateTime.UtcNow + TimeSpan.FromMinutes(1);

            while (true)
            {
                try
                {
                    _connection.Open();
                    _connection.Close();
                    return(true);
                }
                catch (SqlException e)
                {
                    if (!retryOnNotExists &&
                        IsDoesNotExist(e))
                    {
                        return(false);
                    }

                    if (DateTime.UtcNow > giveUp ||
                        !RetryOnExistsFailure(e, ref retryCount))
                    {
                        throw;
                    }
                }
            }
        }
        private bool Exists(bool retryOnNotExists)
        => ExecutionStrategyFactory.Create().Execute(
            giveUp =>
        {
            var retryCount = 0;
            while (true)
            {
                try
                {
                    _connection.Open();
                    _connection.Close();
                    return(true);
                }
                catch (SqlException e)
                {
                    if (!retryOnNotExists &&
                        IsDoesNotExist(e))
                    {
                        return(false);
                    }

                    if (DateTime.UtcNow > giveUp ||
                        !RetryOnExistsFailure(e, ref retryCount))
                    {
                        throw;
                    }

                    Thread.Sleep(100);
                }
            }
        }, DateTime.UtcNow + TimeSpan.FromMinutes(1));
Esempio n. 5
0
        private bool Exists(bool retryOnNotExists)
        {
            var retryCount = 0;

            while (true)
            {
                try
                {
                    _connection.Open();
                    _connection.Close();
                    return(true);
                }
                catch (SqlException e)
                {
                    if (!retryOnNotExists &&
                        IsDoesNotExist(e))
                    {
                        return(false);
                    }

                    if (!RetryOnExistsFailure(e, ref retryCount))
                    {
                        throw;
                    }
                }
            }
        }
Esempio n. 6
0
        private bool Exists(bool retryOnNotExists)
        => Dependencies.ExecutionStrategyFactory.Create().Execute(
            DateTime.UtcNow + RetryTimeout, giveUp =>
        {
            while (true)
            {
                try
                {
                    using (new TransactionScope(TransactionScopeOption.Suppress))
                    {
                        _connection.Open(errorsExpected: true);
                        _connection.Close();
                    }

                    return(true);
                }
                catch (SqlException e)
                {
                    if (!retryOnNotExists &&
                        IsDoesNotExist(e))
                    {
                        return(false);
                    }

                    if (DateTime.UtcNow > giveUp ||
                        !RetryOnExistsFailure(e))
                    {
                        throw;
                    }

                    Thread.Sleep(RetryDelay);
                }
            }
        });
Esempio n. 7
0
        public SqlServerSender(ISqlServerConnection connection, ISqlServerCommand command)
        {
            _connection = connection;
            _connection.Open();

            _command = command;
        }
Esempio n. 8
0
        private bool Exists(bool retryOnNotExists)
        => Dependencies.ExecutionStrategyFactory.Create().Execute(
            giveUp =>
        {
            while (true)
            {
                try
                {
                    _connection.Open();
                    _connection.Close();
                    return(true);
                }
                catch (SqlException e)
                {
                    if (!retryOnNotExists &&
                        IsDoesNotExist(e))
                    {
                        return(false);
                    }

                    if (DateTime.UtcNow > giveUp ||
                        !RetryOnExistsFailure(e))
                    {
                        throw;
                    }

                    Thread.Sleep(RetryDelay);
                }
            }
        }, DateTime.UtcNow + RetryTimeout);
        private bool Exists(bool retryOnNotExists)
        => Dependencies.ExecutionStrategyFactory.Create().Execute(
            DateTime.UtcNow + RetryTimeout, giveUp =>
        {
            while (true)
            {
                var opened = false;
                try
                {
                    using var _ = new TransactionScope(TransactionScopeOption.Suppress);
                    _connection.Open(errorsExpected: true);
                    opened = true;

                    _rawSqlCommandBuilder
                    .Build("SELECT 1")
                    .ExecuteNonQuery(
                        new RelationalCommandParameterObject(
                            _connection,
                            null,
                            null,
                            Dependencies.CurrentContext.Context,
                            Dependencies.CommandLogger));

                    return(true);
                }
                catch (SqlException e)
                {
                    if (!retryOnNotExists &&
                        IsDoesNotExist(e))
                    {
                        return(false);
                    }

                    if (DateTime.UtcNow > giveUp ||
                        !RetryOnExistsFailure(e))
                    {
                        throw;
                    }

                    Thread.Sleep(RetryDelay);
                }
                finally
                {
                    if (opened)
                    {
                        _connection.Close();
                    }
                }
            }
        });
        public virtual void Open()
        {
            PreOpen();

            _realConnection.Open();
        }
        public virtual bool Open()
        {
            PreOpen();

            return(_realConnection.Open());
        }