Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

A way to auto disconnect all connections to a database in SQLsrv2005? And self intro Expand / Collapse
Author
Message
Posted Tuesday, May 7, 2013 7:50 PM


Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, April 28, 2014 5:54 PM
Points: 8, Visits: 23
Hi.

I am new to the forums.

Thank you for having me.

I have provided some bio info in my profile for those interested in personal stuff.

My question:

Is it possible to schedule a nightly process to disconnect all live connections to a database? I am asking this because sometime we need to detach databases for maintenance requirements, and re-attach them again.

I am new to SQL server to be honest, and I personally prefer to use TOAD for SQL Server (a front-end from Quest software).

Thanks in advance and look forward to learning a lot here.

Cheers from Australia!


http://www.tecnq.com.au
Post #1450385
Posted Wednesday, May 8, 2013 12:56 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, July 25, 2014 8:20 PM
Points: 112, Visits: 802

My question:

Is it possible to schedule a nightly process to disconnect all live connections to a database? I am asking this because sometime we need to detach databases for maintenance requirements, and re-attach them again.

I am new to SQL server to be honest, and I personally prefer to use TOAD for SQL Server (a front-end from Quest software).

Thanks in advance and look forward to learning a lot here.

Cheers from Australia!


-------
Here's one way. There are several options and this may not be the best, link is included for your reference.

This will set the database offline, and rollback any transactions in progress immediately, assuming you can.

ALTER DATABASE [DBNAMEgoesHERE] SET OFFLINE WITH ROLLBACK IMMEDIATE

http://msdn.microsoft.com/en-us/library/bb522682.aspx

Hope that helps? Aloha!


--------------------------------------------------
...0.05 points per day since registration... slowly crawl up to 1 pt per day hopefully
Post #1450425
Posted Wednesday, May 8, 2013 4:38 PM


Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, April 28, 2014 5:54 PM
Points: 8, Visits: 23
Thank you for your reply.

However, this does not answer my question exactly.

What I am after is a way to say to the database, ".. at 6pm tonight I want you to disconnect all active connections (roll back is good) and be idle (open?) after all connections have severed."

The MSDN documentation doesn't seem to offer such a feature.

Thanks


http://www.tecnq.com.au
Post #1450828
Posted Thursday, May 9, 2013 2:07 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, July 25, 2014 8:20 PM
Points: 112, Visits: 802
TecNQ (5/8/2013)
Thank you for your reply.

However, this does not answer my question exactly.

What I am after is a way to say to the database, ".. at 6pm tonight I want you to disconnect all active connections (roll back is good) and be idle (open?) after all connections have severed."

The MSDN documentation doesn't seem to offer such a feature.

Thanks


I missed the portion asking about time. Have you worked with SQL Server Agent before? You can schedule jobs within the SQL Server agent to accomplish your goal maybe?

This requires creating SQL Agent Job, which allows you to schedule a specific time to schedule tasks.

http://technet.microsoft.com/en-us/library/ms189237.aspx


--------------------------------------------------
...0.05 points per day since registration... slowly crawl up to 1 pt per day hopefully
Post #1450927
Posted Thursday, May 9, 2013 8:16 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, July 28, 2014 12:02 PM
Points: 30, Visits: 869
I'd set up a SQL Agent job scheduled for whatever time you need this to happen.

One step that executes:

USE <database_name>;

BEGIN
ALTER DATABASE <database_name> SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
ALTER DATABASE <database_name> SET MULTI_USER;
END

Quick and dirty, but it works.

I've also seen an approach that kills sessions in a loop based on the output of sp_who2, but its a complete pita if you have an app that wants to maintain a connection.
Post #1451142
Posted Thursday, May 9, 2013 4:05 PM


Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, April 28, 2014 5:54 PM
Points: 8, Visits: 23
Thanks guys. I didn't know of the SQL Agent. I'll try it out and let you know how I went. Cheers

http://www.tecnq.com.au
Post #1451365
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse