I was hoping to have this issue resolved, but I just can't seem to get out of the gate. I must be doing it wrong. I open my project and enter the above code into stored procedures. In attempting to save it, I receive either an "incorrect parameter" or "you can't change the object type" message. An annoying question that I have is this: A procedure call to detach a dB from the Master makes sense to me, but how do I detach the dB that I'm calling the procedure from? To clairify this, if I was removing Pubs, it doesn't make sense to me to first load Pubs and then enter the procedure to detach it. Maybe that is the way it is done, but it seems odd that a dB should detach itself. I tried it from an alternative dB just to see, but that doesn't work either.
One version of code obtained from SQL Server magazine does at least save for me, but I always receive the "Database not here" error.
Alter Procedure msp_DetachLocalPubs
AS
IF (SELECT Name FROM master..sysdatabases WHERE Name='pubs')
IS NULL
RAISERROR 50000 'Database not here.'
Else
Exec sp_detach_db 'pubs'
I do of course replace Pubs with my dB name, which only leads me to another question: In the sql7/data file my dB file are all concantenated SQL, Do I include this addition? I'm also uncertain about this code because I havn't found "DetachLocal" in BOL or any of my other references.
Another bit of code I tried with the same result was this:
EXEC sp_detach_db @dbname = 'DatabaseName' , @skipchecks = 'true'
I've invested a lot of hours trying to solve this. If you can help me, please assume that I know next to nothing, because that is close to the truth.
At least the attach code seems that it may work, I tried and at least got the intelligent response that the dB was already attached, but then, I was calling it from the dB that I was suppose to be attaching. This approach has really got me confused. Any help?