Last post Jun 24, 2011 10:48 AM by priyesh pandit
Apr 19, 2008 02:12 PM|Simon Deshaies|LINK
How do you close the connection at the SQL Server? I have a backup I want to resotre to SQLExpress using SQL Management Studio Express. When I try, the SQL tells me he can't because the database is in use. I don't realy care about this I still want to restore
the database. So I figured it's because there are some active connection to the database. My gues is I have to close those, but how? I also know I can restart SQLExpress and the connection will drop, but this server has more then one database, so I cant always
do that. I'm looking for some T-SQL like DROP ALL CONNECTION.
Thanks for the help.
Apr 19, 2008 02:32 PM|ashrafur|LINK
Is there any chance that you have already run your application which is using this database and you have bot stop running this yet?
Apr 19, 2008 02:47 PM|ramireddyindia|LINK
to restore database, you need to stop the database.
for that you have to select the servername, right click it-> click stop(not disconnect). then do the restoring.
Apr 19, 2008 03:00 PM|Simon Deshaies|LINK
Is there any chance that you have already run your application which is using this database
Yes I am running the application, it's on a web server hosting many sites, I want to avoid stoping IIS.
servername, right click it-> click stop(not disconnect).
If I stop the SQL Server I stop all the databases and clients won't be happy. So it's not an option.
Is there a way to close the connection at the SQL Server for a specific database?
Apr 23, 2008 04:51 PM|andrewdothay|LINK
I launched Microsoft SQL Server Management Studio and had it generate the T-SQL for me, then I copied that to my setup and tear-down scripts.
Here's the T-SQL script it generated:
EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = N'foo'
ALTER DATABASE [foo] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
ALTER DATABASE [foo] SET SINGLE_USER
Jun 24, 2011 10:48 AM|priyesh pandit|LINK
yes you can