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


Why such a delay in the commit?


Why such a delay in the commit?

Author
Message
pbarbee
pbarbee
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 17
I have a scheduled job (.Net, WinOS Task Scheduler) which completes shortly after it's called but the SQL work it should accomplish in real time does not happen until several hours later.

The .Net scheduled job calls a stored procedure which updates 2 "top level" tables and outputs 3 data readers (that's what they are to the .Net program). Both updated tables have 2 update triggers each (one trigger inserts to a log table & one manages some computed fields in "quick search" tables). One of the fields updated in each table is a datetime field - set to getdate() within the sproc. Temp tables are used to identify the rows to be updated. Quick pseudo-code (showing just one update and select statement):
----
declare @mydate dateime
set @mydate = getdate()

declare @UpdateIDs table(MyID int)

insert @UpdateIDs
select CaseID
from TopLevelTable1
where ...

begin transaction

update TopLevelTable1
set Flag1 = [new value]
, Flag1Date = @mydate
where CaseID in (select MyID from @UpdateIDs)
-- 2 triggers are fired in conjunction with this statement

commit transaction

select [several fields]
from @UpdateIDs t
inner join [several joins from temp table]
----

The problem: the .Net program runs at 11p each night and completes in about 20 seconds. It sends out an email for each row in the select and one to me regarding the ending status. All those emails happen at 11p. The job reports success.

But the time stamp (the param @mydate & the field TopLevelTable1.Flag1Date) is 6am the next day. The trigger inserting to TopLevelTable1_Log has a field LogDate which is set to getdate() within the trigger and its value is also 6am.

There is no other maintenance work being done at that time. Transaction logs (using sqllogship.exe) are being done and full database backup is done at 1:45am. That full backup has the unmodified rows relating to the this job.

What could be happening?
Igor Micev
Igor Micev
SSCertifiable
SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)

Group: General Forum Members
Points: 5920 Visits: 5084
Hi,

We had similar problem recently. Do you have the option "with recompile" in your stored procedure? We've resolved it by attaching that option to the sp.

Regards
IgorMi

Igor Micev,
SQL Server developer at Seavus
My blog: www.igormicev.com
Seraj Alam-256815
Seraj Alam-256815
SSC Veteran
SSC Veteran (206 reputation)SSC Veteran (206 reputation)SSC Veteran (206 reputation)SSC Veteran (206 reputation)SSC Veteran (206 reputation)SSC Veteran (206 reputation)SSC Veteran (206 reputation)SSC Veteran (206 reputation)

Group: General Forum Members
Points: 206 Visits: 373
hi,

I belive there is error within transaction and transaction is not committed. can you add error handling within the transaction to check if there is any.

Alternately, add test line just after commit to check if opentransactions are there. update some flag in either case to know transaction status. Hope this will narrow down to the reason.

btw, is the trigger updating the same table? if yes, what is nested triggers setting?

Seraj Alam
wolfkillj
wolfkillj
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1464 Visits: 2582
pbarbee (4/18/2013)
I have a scheduled job (.Net, WinOS Task Scheduler) which completes shortly after it's called but the SQL work it should accomplish in real time does not happen until several hours later.

The .Net scheduled job calls a stored procedure which updates 2 "top level" tables and outputs 3 data readers (that's what they are to the .Net program). Both updated tables have 2 update triggers each (one trigger inserts to a log table & one manages some computed fields in "quick search" tables). One of the fields updated in each table is a datetime field - set to getdate() within the sproc. Temp tables are used to identify the rows to be updated. Quick pseudo-code (showing just one update and select statement):
----
declare @mydate dateime
set @mydate = getdate()

declare @UpdateIDs table(MyID int)

insert @UpdateIDs
select CaseID
from TopLevelTable1
where ...

begin transaction

update TopLevelTable1
set Flag1 = [new value]
, Flag1Date = @mydate
where CaseID in (select MyID from @UpdateIDs)
-- 2 triggers are fired in conjunction with this statement

commit transaction

select [several fields]
from @UpdateIDs t
inner join [several joins from temp table]
----

The problem: the .Net program runs at 11p each night and completes in about 20 seconds. It sends out an email for each row in the select and one to me regarding the ending status. All those emails happen at 11p. The job reports success.

But the time stamp (the param @mydate & the field TopLevelTable1.Flag1Date) is 6am the next day. The trigger inserting to TopLevelTable1_Log has a field LogDate which is set to getdate() within the trigger and its value is also 6am.

There is no other maintenance work being done at that time. Transaction logs (using sqllogship.exe) are being done and full database backup is done at 1:45am. That full backup has the unmodified rows relating to the this job.

What could be happening?


Have you confirmed that your time zone settings are consistent across servers? SQL Server gets the getdate() value from the OS of the server on which it runs. If your mail server has a different time zone setting, the time of the e-mails will be offset from the getdate() value in SQL Server. If all the code you describe runs in the same batch or on the same connection, you won't get any data back from the SELECT at the end until the INSERT and UPDATE statements are committed, so they must be finished when the e-mail process gets the rows from the SELECT.

P.S. - You would see the offsets you describe if your mail server uses the local time for either the US Mountain or US Pacific time zone and your SQL Server uses UTC time (depending on daylight savings settings).

Jason Wolfkill
Blog: SQLSouth
Twitter: @SQLSouth
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