473,404 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Muiltiple Stored Procedure Within Transaction

How can I code a stored procedure "within my codebehind page" that execute
two or more stored procedures within a transaction?
if so how would I pass values to each parameter?

i.e.
Begin Tran
exec sp1
exec sp2
Commit Tran
.....of course some error checking.
Nov 18 '05 #1
2 1988
Rob
On Thu, 14 Oct 2004 09:09:56 -0500, "Leon" <vn*****@msn.com> wrote:
How can I code a stored procedure "within my codebehind page" that execute
two or more stored procedures within a transaction?
if so how would I pass values to each parameter?

i.e.
Begin Tran
exec sp1
exec sp2
Commit Tran
....of course some error checking.


Fairly straight-forward:

// 1) Create your database connection
IDbConnection dbConn = new
(System.Data.SqlClient.SqlConnection("connection string");

// 2) Create a transaction object
IDbTransaction dbTrans = myConn .BeginTransaction();

// 3) Execute your stored procedures, passing transaction object as
parameter
IDbCommand cmd = dbConn .CreateCommand();
cmd.CommandText = "stored procedure name";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Transaction = dbTrans;

// 4) Add any parameters here
IDataParameter parameter = cmd.CreateParameter();
parameter.ParameterName = CreateCollectionParameterName("param name");
parameter.DbType = DbType.(whatever);
parameter.Value = (whatever);
cmd.Parameters.Add(parameter);

// 5) Execute command
cmd.ExecuteNonQuery(); // or cmd.ExecuteReader or cmd.ExecuteScalar

// 6) Repeat 3), 4) & 5) for next procedure

// 7) Commit the transaction if sucessful otherwise rollback
if (success)
dbTrans.Commit()
else
dbTrans.Rollback()
Nov 18 '05 #2
I'm sorry, I want all of my transaction code within my stored procedure.

"Rob" <**Please post reply to gr*****@nowhere.com> wrote in message
news:lo********************************@4ax.com...
On Thu, 14 Oct 2004 09:09:56 -0500, "Leon" <vn*****@msn.com> wrote:
How can I code a stored procedure "within my codebehind page" that
execute
two or more stored procedures within a transaction?
if so how would I pass values to each parameter?

i.e.
Begin Tran
exec sp1
exec sp2
Commit Tran
....of course some error checking.


Fairly straight-forward:

// 1) Create your database connection
IDbConnection dbConn = new
(System.Data.SqlClient.SqlConnection("connection string");

// 2) Create a transaction object
IDbTransaction dbTrans = myConn .BeginTransaction();

// 3) Execute your stored procedures, passing transaction object as
parameter
IDbCommand cmd = dbConn .CreateCommand();
cmd.CommandText = "stored procedure name";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Transaction = dbTrans;

// 4) Add any parameters here
IDataParameter parameter = cmd.CreateParameter();
parameter.ParameterName = CreateCollectionParameterName("param name");
parameter.DbType = DbType.(whatever);
parameter.Value = (whatever);
cmd.Parameters.Add(parameter);

// 5) Execute command
cmd.ExecuteNonQuery(); // or cmd.ExecuteReader or cmd.ExecuteScalar

// 6) Repeat 3), 4) & 5) for next procedure

// 7) Commit the transaction if sucessful otherwise rollback
if (success)
dbTrans.Commit()
else
dbTrans.Rollback()

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: M Wells | last post by:
Hi All, I don't know if this is a truly esoteric question, or not, but I'm wondering how (or even if) you handle a timeout on a transaction within a stored procedure executed in a Stored...
1
by: Ryan | last post by:
We have a suppliers application that runs a stored procedure (one of many). This stored procedure then calls various other ones etc... and the final number of stored procedures run is 11. Now,...
7
by: Andrew Mayo | last post by:
Here's a really weird one for any SQL Server gurus out there... We have observed (SQL Server 2000) scenarios where a stored procedure which (a) begins a transaction (b) inserts some rows into...
8
by: Thomasb | last post by:
With a background in MS SQL Server programming I'm used to temporary tables. Have just started to work with DB2 ver 7 on z/OS and stumbled into the concept of GLOBAL TEMPORARY TABLE. I have...
3
by: Mark | last post by:
If a java applicaiton using the type 4 driver calls a DB2 stored procedure, does the stored procedure need to do its own commit when updates are completed? If the stored procedure does a commit or...
2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
7
by: Siv | last post by:
Hi, I have a stored procedure that I want to execute and then wait in a loop showing a timer whilst it completes and then carry on once I get notification that it has completed. The main reason...
5
by: byahne | last post by:
We just went live today with a production SQL Server 2005 database running with our custom Java application. We are utilizing the jTDS open source driver. We migrated our existing application...
6
by: BostonNole | last post by:
I am using SQL 2000 and VB.NET (VS 2005). I have three stored procedure: sp_A, sp_B and sp_C I need to be able to call sp_A once and sp_B and sp_C 1 to n number of times all within a single...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.