How to Drop Database in SQL Server when the users are connected to a SQL Server Database. You may need to closing existing connections in a database before restoring the database, before detaching database, get database in SINGLE_USER mode etc.
If you try dropping a database when users are connected to the SQL Server Database you will receive the below mentioned error message.
Error Message
Drop failed for Database 'RajDB'. (Microsoft.SqlServer.Smo)
Cannot drop database "" because it is currently in use. (Microsoft SQL Server, Error: 3702)
Cannot drop database "" because it is currently in use. (Microsoft SQL Server, Error: 3702)
USE [master]
GO
ALTER DATABASE RajDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
/* Query to Drop Database in SQL Server */
DROP DATABASE RajDB
GO
Comments
Post a Comment