Wednesday, March 7, 2012

Closing all connections

How do I set up a job so that I close all open database connections? I think we have a leak in our code which causes our DB to go down (max connections used) roughly once every month, so we just restart the SQL server. Until we can find the exact problem I'd like to do this.

For simplicities sake let's say my database name is just "test."

Thank you.I've seen 2 ways to do this:

1) an ALTER DATABASE command, setting the database into single user mode and kicking out all connections

ALTER DATABASE Test
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE

followed by a

ALTER DATABASE Test
SET MULTI_USER

2) a stored procedure which loops through a cursor of all connections and KILLs them. For example code, look here:Kill all the Active Connections to Your Database.

Terri|||Thank you for your help. Sorry for the immensely delayed response. Things have been far beyond hectic lately.

As far as method 2, do you know how to check how many connections are active? I wanna know if killing it actually DID close the connections.|||I believe you can use sp_who to see this information, and sp_who2 to see more detail.

Terri|||Thank you very much tmorton.

No comments:

Post a Comment