Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Transaction over multiple Job Steps

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-09-25 : 07:21:41
Keith writes "I am trying to find out how to wrap several steps of a SQL 2000 Job (also tried it on 2005) into a transaction.

For example my SQL Job has the following steps:
steps 1 through 4 - do some processing
step 5 - Begin Transaction TransName
steps 6 through 10 - run some other stored procedures that add/update or delete some information in the database. If any of these steps fail the job will skip to step 12 other wise they will proceed to step 11.
step 11 - Commit Transaction TransName
step 12 - Rollback Transaction TransName

This does not work, steps 11 or 12 will give an error message "Msg 3902, Level 16, State 1, Line 2
The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION."

My thoughts are that this is because the transaction is started in one step (which is a separate session that is ended at the end of the step) and when it gets to the other step (which is another session) it does not see that a transaction exists.

I have also tried testing this by having two SQL query windows open and on one of the windows, I start the transaction and on the second window, I try to rollback the transaction but it gives the error mentioned above.

Do you know of a way to make the transaction in a SQL Job work?

Thanks."

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-09-25 : 08:46:23
Do your transaction in one job step.





CODO ERGO SUM
Go to Top of Page

keithlunevich
Starting Member

3 Posts

Posted - 2006-10-03 : 14:18:14
I can not combine all of the steps into one for the transaction, as each of these steps need to be started, do their processing and then finish before the next step can start. This is due to table constraints. If all of the steps are combined into one then this sequential order will not happen.

I have been told to move it into a DTS package and I might try this but I would definitely prefer not to have to rewrite everything.

Does anyone else know of another way to use a single transaction over multiple job steps?

Thanks,
Keith
Go to Top of Page
   

- Advertisement -