Does anyone have a script I can automate that will 1) Check for inactive db connections, 2) Kill those inactive db connections?
Thanks,
Warren
DECLARE @.sql varchar(4000)
WHILE 1=1
BEGIN
SET @.sql = (SELECT TOP 1 'KILL ' + CAST(spid AS VARCHAR(10))
FROM master.dbo.sysprocesses WHERE DATEDIFF(hh, last_batch,
GETDATE()) >= 6
AND spid <> @.@.spid AND spid >= 50)
IF @.sql IS NULL BREAK
EXEC (@.sql)
END
Just schedule it as a job to run at regular intervals. It kills all
processes that have been inactive for more than 6 hours.
Jacco Schalkwijk
SQL Server MVP
"Warren" <anonymous@.discussions.microsoft.com> wrote in message
news:AFF451DE-ADDC-4244-B10A-697A37706CFC@.microsoft.com...
> Does anyone have a script I can automate that will 1) Check for inactive
db connections, 2) Kill those inactive db connections?
> Thanks,
> Warren
|||Thanks Jacco!!!!
Warren
Showing posts with label inactive. Show all posts
Showing posts with label inactive. Show all posts
Friday, March 23, 2012
Script to check inactive db connections
Does anyone have a script I can automate that will 1) Check for inactive db
connections, 2) Kill those inactive db connections?
Thanks,
WarrenDECLARE @.sql varchar(4000)
WHILE 1=1
BEGIN
SET @.sql = (SELECT TOP 1 'KILL ' + CAST(spid AS VARCHAR(10))
FROM master.dbo.sysprocesses WHERE DATEDIFF(hh, last_batch,
GETDATE()) >= 6
AND spid <> @.@.spid AND spid >= 50)
IF @.sql IS NULL BREAK
EXEC (@.sql)
END
Just schedule it as a job to run at regular intervals. It kills all
processes that have been inactive for more than 6 hours.
Jacco Schalkwijk
SQL Server MVP
"Warren" <anonymous@.discussions.microsoft.com> wrote in message
news:AFF451DE-ADDC-4244-B10A-697A37706CFC@.microsoft.com...
> Does anyone have a script I can automate that will 1) Check for inactive
db connections, 2) Kill those inactive db connections?
> Thanks,
> Warren|||Thanks Jacco!!!!
Warren
connections, 2) Kill those inactive db connections?
Thanks,
WarrenDECLARE @.sql varchar(4000)
WHILE 1=1
BEGIN
SET @.sql = (SELECT TOP 1 'KILL ' + CAST(spid AS VARCHAR(10))
FROM master.dbo.sysprocesses WHERE DATEDIFF(hh, last_batch,
GETDATE()) >= 6
AND spid <> @.@.spid AND spid >= 50)
IF @.sql IS NULL BREAK
EXEC (@.sql)
END
Just schedule it as a job to run at regular intervals. It kills all
processes that have been inactive for more than 6 hours.
Jacco Schalkwijk
SQL Server MVP
"Warren" <anonymous@.discussions.microsoft.com> wrote in message
news:AFF451DE-ADDC-4244-B10A-697A37706CFC@.microsoft.com...
> Does anyone have a script I can automate that will 1) Check for inactive
db connections, 2) Kill those inactive db connections?
> Thanks,
> Warren|||Thanks Jacco!!!!
Warren
Subscribe to:
Posts (Atom)