Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert Into Exec w/ Transaction

Status
Not open for further replies.

Tarwn

Programmer
Mar 20, 2001
5,787
US
This is my situation. I am in the process of automating several warehouse transactions that currently are done via hand scanner + proprietary DLL that in turn calls a series of stored procedures. The goal is to allow another layer of stored procedures to call the existing ones instead of using the DLL so I can have the warehouse transactions executed from a PLC. I cannot alter the original procedure as the hand scanners will still be in use and will be the failback if the automation runs into an unrecoverable error.

The existing Procedure that currently handles placing the box on a skid is roughly 300 lines of very convoluted logic that handles several layers of validation and insert/updates about 3-5 tables. Inside the execution phases of the procedure it uses a transaction and rollback for any errors that occur. In the event of a validation error or insertion/update error it returns two text fields, in the event of successful completion it returns 4 text fields. It appears there is hardcoded program logic in the proprietary DLL that relies on these fields to be presented in this fashion.

The automated procedure I am writing calls this procedure with an INSERT INTO to capture the result so I can include the error message in my own return value (integer error code, text description of error).

Unfortunately I receive the error message that I cannot use the ROLLBACK statement within an INSERT-EXEC statement. From the little amount of research I have done so far, it appears my only option will be to either:
a) Change my entire error handling scheme to transparently pass their results back
b) Duplicate and modify their procedure
c) rewrite the critical portions of their procedure as a new one

My hope is that someone will have a better suggestion on how to handle the INSERT-Exec/Rollback situation.

I would post the procedures, but don't believe they are necessary for this question (and wouldn't want to submit you guys to the fun logic that starts with "If Not Exists (Select Null From" that I am working with.

-T
 
Whoops, just noticed I missed a semi-important piece of data, this is SQL Server 2000.
 
Have to go out, but here is an excerpt for you

INSERT-EXEC does not start an implicit transaction on some SQL Server versions. This applies only if: 1) you have SQL 2000 SP3 or earlier or SQL 7, and 2) you run with SET IMPLICIT_TRANSACTIONS ON. With this setting, an INSERT statement should start a transaction, but because of a bug this does not happen with INSERT-EXEC. This bug is fixed in SQL 2000 SP4 and SQL 2005. It is not present in SQL 6.5.

read the whole thing here


Denis The SQL Menace
--------------------
SQL Server Code,Tips and Tricks, Performance Tuning
SQLBlog.com, Google Interview Questions
 
Hmm, I think I read that article earlier. I actually managed to re-write the majority of the crazy logic in 2 hours, but if I have some time later I will un-comment the original INSERT-EXEC logic and see if changing the implicit transactions setting explicitly (heh) does the trick. As much as I dislike their code I would prefer to not have the same logic in two places for this particular transaction.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top