|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Today @ 1:54 AM
Points: 182,
Visits: 942
|
|
Is it possible to update 2 Db with 2 different sqlConnections under same Transaction ?
Thanks.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 7:31 AM
Points: 6,703,
Visits: 11,731
|
|
Not under the same transaction, but you can manage that on your own.
Connection 1: BEGIN TRAN Connection 2: BEGIN TRAN Connection 1: Modify some data Connection 2: Modify some data
-- If modifications on connection 1 and 2 both succeed without error -- Connection 2: COMMIT TRAN Connection 1: COMMIT TRAN
-- If modifications on connection 1 or 2 both encounter an error -- Connection 2: ROLLBACK TRAN Connection 1: ROLLBACK TRAN
You could also look into leveraging the DTC (Distributed Transaction Coordinator). It is much more robust and does similar steps to what I have shown for you automatically. It can also work across different physical servers as well, and not only for database operations.
__________________________________________________________________________________________________ There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Believe you can and you're halfway there. --Theodore Roosevelt
Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein
The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein
1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Tuesday, March 26, 2013 8:41 AM
Points: 2,562,
Visits: 3,451
|
|
this can put more light here
CREATE LOGIN login1 WITH PASSWORD = 'J345#$)thb'; CREATE LOGIN login2 WITH PASSWORD = 'Uor80$23b'; GO CREATE USER user1 FOR LOGIN login1; CREATE USER user2 FOR LOGIN login2; GO begin tran t GRANT IMPERSONATE ON USER:: user2 TO user1; SELECT SUSER_NAME(), USER_NAME(); EXECUTE AS user = 'user2'; REVERT;
GRANT IMPERSONATE ON USER:: user1 TO user2; SELECT SUSER_NAME(), USER_NAME(); EXECUTE AS user = 'user1'; revert; rollback tran t
-------Bhuvnesh---------- While 1 = 1 (Learning SQL....) Click to get fast response of your post
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Today @ 1:54 AM
Points: 182,
Visits: 942
|
|
if connection 2: COMMIT TRAN is done initially (in code) and some err in connection 1 then connection 2: cannot not be rolled back right ?
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 7:31 AM
Points: 6,703,
Visits: 11,731
|
|
winmansoft (3/6/2013) if connection 2: COMMIT TRAN is done initially (in code) and some err in connection 1 then connection 2: cannot not be rolled back right ? Correct. That's why you do leave TRAN on Conn 1 open while you do work on Conn 2, and then issue the commits one after the other. If the work succeeded, the COMMIT is almost guaranteed to succeed.
__________________________________________________________________________________________________ There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Believe you can and you're halfway there. --Theodore Roosevelt
Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein
The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein
1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
|
|
|
|