SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


A way to auto disconnect all connections to a database in SQLsrv2005? And self intro


A way to auto disconnect all connections to a database in SQLsrv2005? And self intro

Author
Message
TecNQ
TecNQ
Forum Newbie
Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 Visits: 24
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
sqlsurfing
sqlsurfing
Old Hand
Old Hand (392 reputation)Old Hand (392 reputation)Old Hand (392 reputation)Old Hand (392 reputation)Old Hand (392 reputation)Old Hand (392 reputation)Old Hand (392 reputation)Old Hand (392 reputation)

Group: General Forum Members
Points: 392 Visits: 1185

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 :-D
TecNQ
TecNQ
Forum Newbie
Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 Visits: 24
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
sqlsurfing
sqlsurfing
Old Hand
Old Hand (392 reputation)Old Hand (392 reputation)Old Hand (392 reputation)Old Hand (392 reputation)Old Hand (392 reputation)Old Hand (392 reputation)Old Hand (392 reputation)Old Hand (392 reputation)

Group: General Forum Members
Points: 392 Visits: 1185
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 :-D
Tony Savoie
Tony Savoie
SSC Rookie
SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)

Group: General Forum Members
Points: 40 Visits: 1037
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.
TecNQ
TecNQ
Forum Newbie
Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 Visits: 24
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search