Mark Deuser
2005-07-20 15:15:20 UTC
Hi all,
In testing some logic to test for suspect databases, I noticed the following
anomaly.
To attempt to create a suspect database condition I:
1. Stopped the SQL Server
2. Renamed mytestdb.mdf to mytestdb.sav
3. Started the SQL Server
The Enterprise Manager greys out the mytestdb database and appends
"(Suspect)" to its name under the Databases folder. Both SQL 7.0 and 2K EM
work in the same way.
However, when I issue the following command (SQL 7.0 and 2K):
SELECT name, status FROM sysdatabases
the status for mytestdb is 1073741840 which according to the online books
means:
1073741840 = 0x40000010
cleanly shutdown (bit 1073741824 - 0x40000000)
torn page detection (bit 16 - 0x10)
I was assuming that the suspect bit (aka "not recovered") bit 0x100 (256)
would have been set. Prior to renaming the database's .mdf file, it's status
was 16 (0x10), so it appears that the renaming the database file caused the
cleanly shutdown bit to be set instead of the suspect bit.
Issuing the command (SQL 2K only):
SELECT DATABASEPROPERTYEX('mytestdb', 'Status')
results in "SUSPECT" being returned. This is what I expected.
Issuing the command (SQL 7.0 and 2K):
SELECT DATABASEPROPERTY(mytestdb', 'IsSuspect')
returns a 0. I was expecting this to return a 1 in this situation.
While DATABASEPROPERTYEX seems to do the trick, it's not available on SLQ
7.0 which I also need to support.
Is the above discrepancy working as designed? If so, what's the best
programmatic way to determine a database is suspect?
Thanks!
Mark
In testing some logic to test for suspect databases, I noticed the following
anomaly.
To attempt to create a suspect database condition I:
1. Stopped the SQL Server
2. Renamed mytestdb.mdf to mytestdb.sav
3. Started the SQL Server
The Enterprise Manager greys out the mytestdb database and appends
"(Suspect)" to its name under the Databases folder. Both SQL 7.0 and 2K EM
work in the same way.
However, when I issue the following command (SQL 7.0 and 2K):
SELECT name, status FROM sysdatabases
the status for mytestdb is 1073741840 which according to the online books
means:
1073741840 = 0x40000010
cleanly shutdown (bit 1073741824 - 0x40000000)
torn page detection (bit 16 - 0x10)
I was assuming that the suspect bit (aka "not recovered") bit 0x100 (256)
would have been set. Prior to renaming the database's .mdf file, it's status
was 16 (0x10), so it appears that the renaming the database file caused the
cleanly shutdown bit to be set instead of the suspect bit.
Issuing the command (SQL 2K only):
SELECT DATABASEPROPERTYEX('mytestdb', 'Status')
results in "SUSPECT" being returned. This is what I expected.
Issuing the command (SQL 7.0 and 2K):
SELECT DATABASEPROPERTY(mytestdb', 'IsSuspect')
returns a 0. I was expecting this to return a 1 in this situation.
While DATABASEPROPERTYEX seems to do the trick, it's not available on SLQ
7.0 which I also need to support.
Is the above discrepancy working as designed? If so, what's the best
programmatic way to determine a database is suspect?
Thanks!
Mark