We know that detach database removed the database from the SQL Server Instance,but the advantage of detach database is the database files are not deleted like in drop database statement.Hence I can copy the same .mdf & .ldf file to some other drive or in fact some other server and attach the same and use it.
Now what if the database is marked as suspect and you want to move the files to some other server and check the same.So you issue a sp_detach_db statement.SQL Server doesnt throw any error and the database is removed from the instance.
And now you copy the same to a new server and you find you are unable to attach the same using sp_attach_db.
Error Message
Server: Msg 1813, Level 16, State 2, Line 1Could not open new database 'UserDB'. CREATE DATABASE is aborted.Device activation error. The physical file name 'C:\C:\Program Files\Microsoft SQL Server\90\Data\UserDB_log.ldf' may be incorrect
Cause
This happens because database was in suspect mode and hence the database shout down was not proper and yoy recieve a 1813 error mentioning the same
Resolution
1) Create database with the same name and also with the same .mdf and .ldf files in the same path
2) Change the database status to offline
3) Overwrite the files from the source server to the destination server
4) Now when you make the database online,the DB should be up or at least it will be in suspect as before
No comments:
Post a Comment