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.
| Author |
Topic |
|
hadoft
Starting Member
20 Posts |
Posted - 2004-03-01 : 08:46:05
|
| i am using a table named TLog to register log infoand I have two stored procedures Proc1, Proc2each of them while doing its job will insert a log data in table (TLog) which has been prepared to hold all log insertsthe problem is that i want to execute these 2 SP in a single transaction,and at the end of the transaction i want to be able to read all log data which has been inserted in table TLog from both Prc1 and Prc2 whether the transaction ended with commit OR rollbackthe problem is: in ROLLBACK case the inserted log data will be rolled back too, so i cant read them at the end of the executionthe idea is that i want to make some inserts out the influence of the transaction although i am in the scop of the transaction, is it possible ??any one can give an advice??please i don't want to give up the TLog because this log method was very very suitable to me.here is a script that will explain the problem:/************************* Begin Create Script *********************/use tempdbCreate table t1(a int,b int,c int)goCreate table TLog(msg varchar(50),No int)goCreate procedure Prc1asbegin insert into TLog(Msg, No) values ('Begin Prc1', 1); -- do some job -- add extra log records to TLog insert into t1(a, b, c) values( 1, 2, 3); -- do some job -- add extra log records to TLog insert into TLog(Msg, No) values ('End Prc1', 1);endgoCreate procedure Prc2asbegin insert into TLog(Msg, No) values ('Begin Prc2', 1); begin tran -- do some job insert into TLog(Msg, No) values ('log info 1', 1); insert into TLog(Msg, No) values ('log info 2', 1); insert into TLog(Msg, No) values ('log info 3', 1); -- add extra log records to TLog insert into t1(a, b, c) values( 4, 5, 6); insert into TLog(Msg, No) values ('log info 4', 1); insert into TLog(Msg, No) values ('log info 5', 1); -- do some job /*for some reason */ rollback; insert into TLog(Msg, No) values ('End Prc2', 1);endgo/************************* End Create Script *********************/begin transaction exec prc1 exec prc2if @@trancount > 0 commit;-- here i want to get all inserted rows in TLog wheater the transaction has been commited or rollbackselect * from TLog-- but i only ge the rows that has been inserted aftre the tran rollback gothanks for your help |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-03-01 : 08:51:21
|
| Have a look at Save Transaction.But you might be better putting an identifier on your entries and doing a delete.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
hadoft
Starting Member
20 Posts |
Posted - 2004-03-01 : 10:05:03
|
quote: Originally posted by nr Have a look at Save Transaction.But you might be better putting an identifier on your entries and doing a delete.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy.
thanks nrbut trans save point is not exactly what i am looking for, cause it will need a lot of overhead work, and a lot of code to be recheckedany other ideas?? |
 |
|
|
|
|
|
|
|