Cannot drop database because it is currently in use

后端 未结 17 1447
北恋
北恋 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:52

    Using MS SQL Server 2008, in DELETE dialog with Close connection options, this is the generated script, I guess it is the best:

    EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = N'YOUR_DATABASE_NAME'
    GO
    USE [master]
    GO
    ALTER DATABASE [YOUR_DATABASE_NAME] SET  SINGLE_USER WITH ROLLBACK IMMEDIATE
    GO
    USE [master]
    GO
    /****** Object:  Database [YOUR_DATABASE_NAME]    Script Date: 01/08/2014 21:36:29 ******/
    DROP DATABASE [YOUR_DATABASE_NAME]
    GO
    

提交回复
热议问题