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


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


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

Author
Message
mujeeb-590324
mujeeb-590324
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 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
jacob sebastian
jacob sebastian
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1460 Visits: 2523
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

.
KennyClarck
KennyClarck
Right there with Babe
Right there with Babe (773 reputation)Right there with Babe (773 reputation)Right there with Babe (773 reputation)Right there with Babe (773 reputation)Right there with Babe (773 reputation)Right there with Babe (773 reputation)Right there with Babe (773 reputation)Right there with Babe (773 reputation)

Group: General Forum Members
Points: 773 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.
Doug S.
Doug S.
SSC Veteran
SSC Veteran (287 reputation)SSC Veteran (287 reputation)SSC Veteran (287 reputation)SSC Veteran (287 reputation)SSC Veteran (287 reputation)SSC Veteran (287 reputation)SSC Veteran (287 reputation)SSC Veteran (287 reputation)

Group: General Forum Members
Points: 287 Visits: 333
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
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