SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On



From vb.net how can I rollback transaction which I created deferent Sql Server... Expand / Collapse
Author
Message
Posted Wednesday, December 26, 2007 3:37 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, October 21, 2009 4:04 AM
Points: 2, Visits: 35
HI

For my application I am using SQL Server2000 and VB.NET,

I use two SQL Server Stored Procedure to create Sales Order, I have two tables for sales order (1 orderheader , 2 orderdetail)

First I create record in orderheader table with Stored Procedure (usp_CreateOrderHeader)

After that I create record in orderdetail table for each items one by one with Stored Procedure (usp_CreateOrderDetail)


My question

How can I roll back all record created in Orderheader table and orderdetail table, if system fail in middle while I create Sales Order transaction from VB..net application

From vb.net how can I rollback transaction which I created deferent Stored Procedure


Thanks
Post #436313
Posted Wednesday, December 26, 2007 5:43 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Yesterday @ 6:53 AM
Points: 421, Visits: 2,301
Personally, I prefer to pass all the data to the stored procedure at once..instead of calling a stored procedure for each record. This will give better performance as well as you can handle the transaction at the database side.

This topic is discussed in detail here:
http://www.sqlservercentral.com/articles/Miscellaneous/2908/
http://www.sqlservercentral.com/articles/Miscellaneous/2909/
http://www.sqlservercentral.com/articles/Miscellaneous/2911/
http://www.sqlservercentral.com/articles/Stored+Procedures/2912/

If you still want to execute stored procedures one by one, you can use the transaction processiong features of ado.net connection. Call connection.beginTransaction() and all the commands that you execute after that will be part of a single transaction. Just google for "ado.net transaction" and there are plenty of resources available.

for example:
http://www.c-sharpcorner.com/UploadFile/shrijeetnair/TransactionsNConcurr09052005002744AM/TransactionsNConcurr.aspx


Jacob Sebastian, SQL Server MVP
http://beyondrelational.com/blogs/jacob/
Post #436318
Posted Monday, January 07, 2008 12:19 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Sunday, January 03, 2010 1:39 AM
Points: 564, Visits: 53
You can try to use System.Data.SqlClient.SqlTransaction object and execute all sp into the same transaction context.
If you catch an error you can rollback all change into the transaction context.
Post #439453
Posted Tuesday, January 08, 2008 8:13 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, May 05, 2009 8:54 AM
Points: 103, Visits: 274
Mujeeb, go to VB.Net help and search on Ado.net Transactions and you will find a good explanation about SQL Server transactions. This link may work.
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEV.v10.en/dnadonet/html/transact.htm

I would not rewrite your procs as others have suggested, just use the SQLConnection object like this:

connection.BeginTransaction()
' perform your inserts here
connection.Commit()

Be sure to use Try Catch blocks and test your rollback logic also.

Good Luck




Doug
Post #440080
« Prev Topic | Next Topic »


Permissions Expand / Collapse