Part of my script runs:
sp_detach_db @dbname, 'true'
When the db is in use the message 'Cannot detach the database 'marktest' because it is currently in use' is displayed in sql server.
How can I catch this error? I already have the ability to log other errors to a text file but I dont know how to capture this type of message!?
Can anyone help?