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); }
public SqlServerDataCursor(IDbContext dbContext) { _dbContext = dbContext; _connection = null; _command = null; _reader = null; }
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); }
public void Close() { if (_reader != null) { _reader.Dispose(); _reader = null; } if (_command != null) { _command.Dispose(); _command = null; } if (_connection != null) { _connection.Close(); _connection = null; } }
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(); } } }
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)); }
public InternalSqlServerCommand(string statement, InternalSqlServerConnection connection) { Command = new SqlCommand(statement); Command.CommandTimeout = 3 * 60 * 60; Command.Connection = connection.Connection; }