コード例 #1
0
ファイル: SqlServerSchema.cs プロジェクト: radtek/ACopy
        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);
        }
コード例 #2
0
 public SqlServerDataCursor(IDbContext dbContext)
 {
     _dbContext  = dbContext;
     _connection = null;
     _command    = null;
     _reader     = null;
 }
コード例 #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);
        }
コード例 #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;
     }
 }
コード例 #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();
                }
            }
        }