Detecting Allocation Errors as Early as Possible

This section provides some strategies for detecting allocation errors 2521, 2540, 2546, 7939, 7940, and 7949 as early as possible:

Without single-user mode, you cannot prevent non-spurious error messages from occurring.


Single-User Mode Method (Spurious and Non-Spurious Errors)

If you can run dbcc checkalloc in single-user mode, replace each occurrence of dbcc checkalloc in scripts and procedures with dbcc checkalloc with the fix option, as follows:

1> use master 
2> go

1> sp_dboption database_name, single, true
2> go

1> use database_name 
2> go

1> checkpoint
2> go

1> use master 
2> go

1> dbcc checkalloc(database_name, fix)
2> go

1> sp_dboption database_name, single, false
2> go

1> use database_name 
2> go

1> checkpoint
2> go

NoteUse dbcc checkalloc with the fix option while in a database other than the one that is being repaired.

Before you implement this strategy, consider these facts:

If you have databases on which you cannot run allocation checks in single-user mode, use the following procedure to eliminate the spurious allocation errors that can occur when dbcc checkalloc is run in multiuser mode.


Multiuser Mode Method (Spurious Errors Only)

If your site does not allow single-user operation (such as a 24-hour production Adaptive Server), you cannot completely prevent spurious allocation errors, but you can prevent spurious errors on the transaction log-where most occur. Use both of the strategies described in this section to stop occurrences of spurious allocation errors.

Strategy 1

Do not run dbcc check commands when performing operations like create index, truncate table, or bcp; or when doing large numbers of inserts into the database.

Strategy 2

Before you implement this strategy, consider these facts:

For this strategy, replace each occurrence of dbcc checkalloc in scripts and procedures with the following:

1> dbcc traceon (2512)
2> go

1> dbcc checkalloc (database_name)
2> go

1> dbcc traceoff (2512)
2> go

1> use database_name 
2> go

1> dbcc tablealloc (syslogs)
2> go

This procedure prevents dbcc checkalloc from examining the syslogs table, where most spurious errors originate (dbcc tablealloc checks syslogs instead). If you get genuine allocation errors, refer to Chapter 3, “Error Message Writeups” for instructions.