Deleting database at runtime

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm using ASP.Net and code behind 'vb'.SQL Server as backend. I want to
delete database at run time. If im deleting the databse using 'DROP DATABASE
databasename' its throwing exception ' Database currently in use'. How to
delete the databse during runtime. I have created a new command and
connection object for deleting the database.And i establish the connection
string to Master database before deleting the database. Please give me some
suggestion.
 
Open a connection to the master database, not the database in question. Run
the following:

select spid from master..sysprocesses where dbid=db_id('DatabaseNameToDrop')

This will give you a list of process connected to the database. You then
have to run a kill command on each process. Rerun to make sure nobody is
connecting. You can now detatch, drop, etc. the database.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
Back
Top