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 12»»

scheduling job Expand / Collapse
Author
Message
Posted Tuesday, March 5, 2013 11:58 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, April 23, 2014 3:06 PM
Points: 319, Visits: 757
Hi friends,

We need to monitor a user session for locks to troubleshoot a problem in the program. When the program is started we would like to schedule a job to check for the locks every 5 minutes and the output should be saved into a new text file for each run.. I use sql query to check the locks and I run this as T-SQL script in a scheduled job but every time the job runs output file is being overwritten.. not sure how to output the results into a new seperate text file when the job runs every 5 minutes...

Any help is greatly appreciated... Thanks a lot for all your help
Post #1426973
Posted Tuesday, March 5, 2013 2:09 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, April 23, 2014 3:06 PM
Points: 319, Visits: 757
Below is the sql query I'm using to check the locks as a scheduled job to run every 5 minutes.. But I would need to create a new seperate output file for every run every 5 minutes..
BCP errors that the query is too long

SELECT
spid = Lock.request_session_id,
HostName = Session.host_name,
ProgramName = Session.program_name,
Cmd = Request.Command,
LoginName = Session.login_name,
dbid = Lock.resource_database_id,
DatabaseName = DB_NAME(Lock.resource_database_id),
Type = Lock.resource_type,
LockType = Lock.request_type,
Mode = Lock.request_mode,
Status = request_status,
UserTable.Name

FROM
sys.dm_tran_locks AS Lock

LEFT JOIN
sys.dm_exec_sessions AS Session ON
Session.session_id = Lock.request_session_id

LEFT JOIN
sys.dm_exec_requests AS Request ON
Request.session_id = Session.session_id

LEFT JOIN
sys.tables AS UserTable ON
UserTable.object_id = Lock.resource_associated_entity_id
AND
type = 'U'

WHERE
Lock.resource_type = 'OBJECT'
go

Please help.. thanks a lot
Post #1427036
Posted Tuesday, March 5, 2013 2:11 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 2:37 PM
Points: 2,828, Visits: 3,012
Under the advanced tab for the job step where you specified the output file, there is a checkbox for "Append output to existing file". Without this box checked the output file will be overwritten each time.
Post #1427038
Posted Tuesday, March 5, 2013 2:14 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, April 23, 2014 3:06 PM
Points: 319, Visits: 757
Hi Jeremy,

I do not want to append it the existing file either.. We would want a new seperate file created when the job runs every 5 minutes... not sure if it can be done may be with a time stamp included in the file name or if there is any other way to do this.. Also is it possible to output the result in a xls/csv format? Please help thanks again
Post #1427041
Posted Tuesday, March 5, 2013 11:14 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 6:57 PM
Points: 7,094, Visits: 12,583
You can use Agent Tokens in your log name.

Using Tokens in Job Steps- SQL Server 2008 R2

Change the log name to something like this:

X:\...path to log files...\filename_$(ESCAPE_NONE(STRTDT))_$(ESCAPE_NONE(STRTTM)).log

And you'll get a file name like this on each run:

filename_20130305_231247.log


__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1427179
Posted Thursday, March 7, 2013 8:56 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, April 23, 2014 3:06 PM
Points: 319, Visits: 757
Thanks a lot. Using tokens worked
Post #1428039
Posted Thursday, March 7, 2013 10:04 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 6:57 PM
Points: 7,094, Visits: 12,583
You're welcome. Thanks for the feedback.

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1428098
Posted Tuesday, March 12, 2013 9:05 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, April 23, 2014 3:06 PM
Points: 319, Visits: 757
Hi Friends,

Thanks for all the help so far.. Is there a way to schedule the job every 20 seconds? I see the default starts from 1 minute and up.. THanks again
Post #1429883
Posted Tuesday, March 12, 2013 9:50 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 6:57 PM
Points: 7,094, Visits: 12,583
You can in 2008 and up, and maybe in later service packs of 2005, but in any case you may not want to do that. In 2005, and in some scenarios still in 2008 and up, queries issued by SQL Agent against msdb bloat the cache significantly. The more often you run jobs, the worse the problem becomes.

http://connect.microsoft.com/SQLServer/feedback/details/526485/dm-exec-cached-plans-bloat

Instead of only scheduling the job to run every 20 seconds, maybe it would be better to have the proc that does the checking use WAITFOR DELAY inside a loop to check the condition every 20 seconds allowing the job to run continuously. The proc would only take action when the condition was detected and would always loop back to the WAITFOR DELAY.


__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1429912
Posted Thursday, March 21, 2013 2:34 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, April 23, 2014 3:06 PM
Points: 319, Visits: 757
Hi friends,

We have a scheduled job set to run every 4 seconds from the time the job is enabled. The below sql in the job runs and appends the results every 4 seconds in the output file. Once the program ends we disable the job.

Would like to know if this can be done in a stored procedure so that it can be called from the program itself and it can be easier to track down when the error occurs.. Please give me your suggestions


SELECT
spid = Lock.request_session_id,
HostName = Session.host_name,
ProgramName = Session.program_name,
Cmd = Request.Command,
LoginName = Session.login_name,
dbid = Lock.resource_database_id,
DatabaseName = DB_NAME(Lock.resource_database_id),
Type = Lock.resource_type,
LockType = Lock.request_type,
Mode = Lock.request_mode,
Status = request_status,
UserTable.Name

FROM
sys.dm_tran_locks AS Lock

LEFT JOIN
sys.dm_exec_sessions AS Session ON
Session.session_id = Lock.request_session_id

LEFT JOIN
sys.dm_exec_requests AS Request ON
Request.session_id = Session.session_id

LEFT JOIN
sys.tables AS UserTable ON
UserTable.object_id = Lock.resource_associated_entity_id
AND
type = 'U'

WHERE
Lock.resource_type = 'OBJECT'
go

Thanks a lot
Post #1434029
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse