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


Transactions


Transactions

Author
Message
IT researcher
 IT researcher
Mr or Mrs. 500
Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)

Group: General Forum Members
Points: 592 Visits: 1798
Is it possible to update 2 Db with 2 different sqlConnections under same Transaction ?

Thanks.
Orlando Colamatteo
Orlando Colamatteo
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15035 Visits: 14396
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
Bhuvnesh
Bhuvnesh
SSCertifiable
SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)

Group: General Forum Members
Points: 5306 Visits: 4076
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----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
IT researcher
 IT researcher
Mr or Mrs. 500
Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)Mr or Mrs. 500 (592 reputation)

Group: General Forum Members
Points: 592 Visits: 1798
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 ?
Orlando Colamatteo
Orlando Colamatteo
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15035 Visits: 14396
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
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