Deleting database at runtime

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.
 
G

Guest

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!
***************************
 
G

Guest

thank you very much, i will try your suggestion. If it works fine then i will
inform you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top