views:

582

answers:

2

when an SQL Server Express DB is 'in recovery', you are unable to connect using SQL Authentication.

Is there a simple way of determining the stat of the DB prior to connecting to it? (Using .Net)

+2  A: 
SELECT DATABASEPROPERTYEX ('master', 'STATUS') AS 'Status';

Replace 'master' with your database name

Andy Irving
+1  A: 

That's kind of a trick question. Instead of connecting to that particular database, you still need to connect to the server itself, but specify a different database. When connecting, your default database might be the one that's in recovery. In that case, you'll need to specify a different database upon connecting, and THEN issue a query to check the database's extended properties.

Unfortunately, this means your SQL login will need permissions to that other database you'll be connecting to, AND it'll need permissions to query the database's extended properties.

Brent Ozar