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


Add to briefcase

From vb.net how can I rollback transaction which I created deferent Sql Server Stored Procedure 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, September 8, 2010 4:03 AM
Points: 2, Visits: 47
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: Tuesday, December 24, 2013 4:42 AM
Points: 460, Visits: 2,523
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


.
Post #436318
Posted Monday, January 7, 2008 12:19 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Wednesday, February 20, 2013 2:42 AM
Points: 739, Visits: 75
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 8, 2008 8:13 AM
SSC-Enthusiastic

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

Group: General Forum Members
Last Login: Today @ 12:30 PM
Points: 115, Visits: 321
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 »

Add to briefcase

Permissions Expand / Collapse