Exemplo n.º 1
0
        public override List <ITableShortInfo> GetTableNames(string searchString)
        {
            string selectStmt = GetStatementForSelectTableNames(searchString);

            List <ITableShortInfo>      tables     = new List <ITableShortInfo>();
            InternalSqlServerConnection connection = null;

            try
            {
                connection = new InternalSqlServerConnection(DbContext.ConnectionString);
                using (InternalSqlServerCommand command = new InternalSqlServerCommand(selectStmt, connection))
                {
                    SqlDataReader reader = command.Command.ExecuteReader(CommandBehavior.CloseConnection);
                    while (reader.Read())
                    {
                        tables.Add(TableShortInfoFactory.CreateInstance(reader.GetString(0), GetRowCount(reader.GetString(0))));
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ADatabaseException("ERROR when getting table names: " + selectStmt, ex);
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }

            return(tables);
        }
Exemplo n.º 2
0
 public SqlServerDataCursor(IDbContext dbContext)
 {
     _dbContext  = dbContext;
     _connection = null;
     _command    = null;
     _reader     = null;
 }
Exemplo n.º 3
0
        public IDataReader ExecuteReader(string selectStatement, bool hasBlobColumn)
        {
            _connection = new InternalSqlServerConnection(_dbContext.ConnectionString);
            _command    = new InternalSqlServerCommand(selectStatement, _connection);
            CommandBehavior behavior = CommandBehavior.Default;

            if (hasBlobColumn)
            {
                behavior |= CommandBehavior.SequentialAccess;
            }
            _reader = _command.Command.ExecuteReader(behavior);

            return(_reader);
        }
Exemplo n.º 4
0
 public void Close()
 {
     if (_reader != null)
     {
         _reader.Dispose();
         _reader = null;
     }
     if (_command != null)
     {
         _command.Dispose();
         _command = null;
     }
     if (_connection != null)
     {
         _connection.Close();
         _connection = null;
     }
 }
Exemplo n.º 5
0
        public static T ExecuteInConnectionScope <T>(IDbContext dbContext, string sql, Func <InternalSqlServerCommand, T> func)
        {
            InternalSqlServerConnection connection = null;

            try
            {
                connection = new InternalSqlServerConnection(dbContext.ConnectionString);
                using (var command = new InternalSqlServerCommand(sql, connection))
                {
                    return(func(command));
                }
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
        }
Exemplo n.º 6
0
        public static T Execute <T>(IDbContext dbContext, string sql, Func <InternalSqlServerCommand, T> func)
        {
            for (int i = 0; i < _maxTries; i++)
            {
                try
                {
                    return(InternalSqlServerConnection.ExecuteInConnectionScope(dbContext, sql, func));
                }
                catch (Exception ex)
                {
                    if (ADatabaseException.ShouldThrottle(ex))
                    {
                        dbContext.Logger.Write(string.Format("Throttling down \"{0}...\", round {1}", sql.Substring(0, Math.Min(sql.Length, 40)), i));
                        Thread.Sleep(10000 + i * i * i * 1000);
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            return(InternalSqlServerConnection.ExecuteInConnectionScope(dbContext, sql, func));
        }
Exemplo n.º 7
0
 public InternalSqlServerCommand(string statement, InternalSqlServerConnection connection)
 {
     Command = new SqlCommand(statement);
     Command.CommandTimeout = 3 * 60 * 60;
     Command.Connection     = connection.Connection;
 }