However, this is an alternative method; in this way, you
write a SQL script and schedule it through SQL Job, in the same way you
schedule your maintenance plans in your SQL Server such as making daily
backups, truncating log files etc.
SQL Script :
USE MyDatabaseDECLARE @EXECSQL varchar(max)
SET @EXECSQL = ''select @EXECSQL = @EXECSQL+ 'Kill ' + Convert(varchar, [Connection ID]) + ';'
From Session WHERE [Application Name]='Microsoft Dynamics NAV Classic client' and [Idle Time]>3000
EXEC(@EXECSQL)
How to schedule the above SQL Script:
Just enable a job. It’s a matter of pasting the code and give the date & time etc. This is similar to Windows scheduler as well.
Steps for scheduling via a SQL Job:
1.
Expand
the SQL Server Agent node and right click the Jobs node in SQL Server Agent and
select 'New Job'
2.
In the
'New Job' window enter the name of the job and a description on the 'General'
tab.
3.
Select 'Steps' on the left hand side of the
window and click 'New' at the bottom.
4.
In the 'Steps' window enter a step name and
select the database you want the query to run against.
5.
Paste in the T-SQL command you want to run into
the Command window and click 'OK'.
6.
Click on the 'Schedule' menu on the left of the
New Job window and enter the schedule information (e.g. daily and a time).
7.
Click 'OK' - and that’s done!!
Special Note: I just thought of posting this into the blog
even for own future references. Thanks very much Isuru (Isuru Dias) for letting
this to me.
Thank you very much for this valuable post!
ReplyDeleteYou are welcome!
Delete