Last post Jun 28, 2014 12:15 AM by neoaguil17
Member
9 Points
112 Posts
Jun 27, 2014 05:45 AM|sri.sri.sri|LINK
Hi all
i have a db1 and db2, i am inserting record in db1, when i am inserting recording in db2 ,if i got the error i have to roll back the db1 inserted record also
how?
transactions
Participant
1644 Points
792 Posts
Jun 27, 2014 05:58 AM|rajesh93180|LINK
This may help you.
BEGIN TRAN @TransactionName INSERT INTO <Table_Name> VALUES(1), (2); ROLLBACK TRAN @TransactionName;
In your scenario, catch the exception and roll back the corresponding transaction in the catch block.
1061 Points
318 Posts
Jun 27, 2014 06:02 AM|Dharmesh.Kotadiya|LINK
for rollback check this url : http://www.codeproject.com/Articles/4451/SQL-Server-Transactions-and-Error-Handling
for insert into another database
INSERT INTO Database2.dbo.MyOtherTable (MyKey, MyValue) values(1,2)
Jun 27, 2014 07:37 AM|sri.sri.sri|LINK
thanks for reply
can u give me some code example
Jun 27, 2014 07:39 AM|sri.sri.sri|LINK
but i need this in asp.net
i need this in asp.net
Jun 27, 2014 07:51 AM|rajesh93180|LINK
sri.sri.sri i need this in asp.net
Do you want to perform rollback from ASP.Net?
Jun 27, 2014 10:09 AM|sri.sri.sri|LINK
yes
Jun 27, 2014 10:16 AM|rajesh93180|LINK
I think you're performing both inserts in a single procedure. right? If so, the above process only works.
175 Points
608 Posts
Jun 28, 2014 12:15 AM|neoaguil17|LINK
Use transactionScope in c#:
using System.Transactions;
using (var scope = new TransactionScope(TransactionScopeOption.Required)) { _dataPaquete.InsertDB1; // insert in server 1
_dataPaquete.InsertDB2; // insert in server 2
scope.Complete(); }
when throw error in server1 or server2, the operation rollback
Read the article: http://www.codeproject.com/Articles/690136/All-About-TransactionScope
Member
9 Points
112 Posts
transaction on two database
Jun 27, 2014 05:45 AM|sri.sri.sri|LINK
Hi all
i have a db1 and db2, i am inserting record in db1, when i am inserting recording in db2 ,if i got the error i have to roll back the db1 inserted record also
how?
transactions
Participant
1644 Points
792 Posts
Re: transaction on two database
Jun 27, 2014 05:58 AM|rajesh93180|LINK
This may help you.
In your scenario, catch the exception and roll back the corresponding transaction in the catch block.
transactions
Mark as answer if you find this post helpful.
Participant
1061 Points
318 Posts
Re: transaction on two database
Jun 27, 2014 06:02 AM|Dharmesh.Kotadiya|LINK
for rollback check this url : http://www.codeproject.com/Articles/4451/SQL-Server-Transactions-and-Error-Handling
for insert into another database
transactions
Dharmesh M. Kotadiya,
Mark as answer if my anwers helps you
Member
9 Points
112 Posts
Re: transaction on two database
Jun 27, 2014 07:37 AM|sri.sri.sri|LINK
thanks for reply
can u give me some code example
transactions
Member
9 Points
112 Posts
Re: transaction on two database
Jun 27, 2014 07:39 AM|sri.sri.sri|LINK
thanks for reply
but i need this in asp.net
transactions
Member
9 Points
112 Posts
Re: transaction on two database
Jun 27, 2014 07:39 AM|sri.sri.sri|LINK
i need this in asp.net
transactions
Participant
1644 Points
792 Posts
Re: transaction on two database
Jun 27, 2014 07:51 AM|rajesh93180|LINK
Do you want to perform rollback from ASP.Net?
transactions
Mark as answer if you find this post helpful.
Member
9 Points
112 Posts
Re: transaction on two database
Jun 27, 2014 10:09 AM|sri.sri.sri|LINK
yes
transactions
Participant
1644 Points
792 Posts
Re: transaction on two database
Jun 27, 2014 10:16 AM|rajesh93180|LINK
I think you're performing both inserts in a single procedure. right? If so, the above process only works.
transactions
Mark as answer if you find this post helpful.
Member
175 Points
608 Posts
Re: transaction on two database
Jun 28, 2014 12:15 AM|neoaguil17|LINK
Use transactionScope in c#:
using System.Transactions;
using (var scope = new TransactionScope(TransactionScopeOption.Required))
{
_dataPaquete.InsertDB1; // insert in server 1
_dataPaquete.InsertDB2; // insert in server 2
scope.Complete();
}
when throw error in server1 or server2, the operation rollback
Read the article: http://www.codeproject.com/Articles/690136/All-About-TransactionScope
transactions