I was trying to detach the DB when it gave me an error that it is currently in use. Hence, I tried to take my DB offline but it failed saying
'an exception occured while executing a transact SQL statement or batch
-> ALTER DATABASE failed because a lock could not be placed on database 'myDB'. Try again later.
ALTER DATABASE statement failed. (Microsoft SQL Server, Error: 5061)'
Now if I try and access the DB it says it is not accessible. What can I do to make my DB accessible again?
My aim was to detach the DB, relocate its secondary database file to a new drive and reattach it (simply because of space issues).
Best Answer
You should never do this using detach. Until we know more about exactly what state your database is in now, for next time, you should do the following:
ALTER DATABASE SET OFFLINE
ALTER DATABASE MODIFY FILE
ALTER DATABASE SET ONLINE
The reason you don't want to do this with detach, and the reason you want to copy the files instead of moving them, is because when something goes wrong in either of those processes, you have exactly 0 copies of your database. Or the situation you're in now.