It is the common issue for DBA, here’s the troubleshooting steps:
STEP1: identify the db status:
use master
select databaseproperty(‘db_name’,'isShutdown’)
Most of them it would return 1 in this situation
STEP2: Clear up the internal db status:
use master
alter database db_name set offline
it would return with no error in most cases
STEP3: Get detail error message:
use master
alter database db_name set online
After step3, sql server will first verify the log file, if the log file is okay, it will verify the rest of the data file(s). Most of time it is because of the file location or file properties setting. For example if it is file location issue:
alter database db_name
modify (file=’logical name’, filename=’physical name’)
go
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Second Approach:
Error 945 is returned when the database is marked IsShutdown. This occurs when a database cannot be recovered due to missing files, or some other resource error that usually can be corrected easily.
Action
First, verify that the database is marked IsShutdown using DATABASEPROPERTY.
Then, determine the cause of the error by consulting the errorlog, and take action as noted below.
If one or more data or log files are missing:
Make the files available and bring the database OFFLINE using ALTER DATABASE.
Use ALTER DATABASE to bring the database ONLINE
If insufficient log space:
Use sp_add_log_file_recover_suspect_db() to add another log file.
The database is recovered and brought online by this procedure.
If insufficient data space:
Use sp_add_data_file_recover_suspect_db() to add another log file.
The database is recovered and brought online by this procedure.
If insufficient memory:
The insufficient memory error can occur when a number of databases are recovered at the same time. Retrying the operation may fix the problem:
Retry the operation using ALTER DATABASE to bring the database OFFLINE.
Use ALTER DATABASE to bring the database ONLINE.
If retrying the operation does not work, consider freeing up memory.