Cannot drop database because it is currently in use

后端 未结 17 1460
北恋
北恋 2020-12-07 11:50

I want to drop a database. I have used the following code, but to no avail.

public void DropDataBase(string DBName,SqlConnection scon)
{
    try
    {
               


        
17条回答
  •  情深已故
    2020-12-07 12:25

    If your dropping the database in SQL Management Studio and you get the message, don't forget that you use Master as selected database otherwise your query is also an connection to the database.

    USE Master;
    GO
    DROP DATABASE AdventureWorks;
    GO
    

提交回复
热议问题