Re: transaction with unknown nbr of commands
- From: "Mary Chipman [MSFT]" <mchip@xxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 30 Aug 2005 15:20:53 -0400
For maximum efficiency and scalability, you should implement your
explicit transaction inside of a stored procedure, not from client
code. The basic idea is you collect *all* input from the user first,
then call your wrapper stored procedure, passing it all of the user
input as input parameters. That stored procedure then initiates an
explicit transaction with a BEGIN TRAN statement, calling the other
stored procedures as required, passing each one the information it
needs. Each stored procedure returns success/failure information in
output parameters, passing back error information to the calling
sproc, which then commits if there are no errors, or rolls back if any
single operation fails. The wrapper sproc then passes success/failure
information back to the client. This requires a single SqlCommand and
1 round trip (assuming you remember to SET NOCOUNT ON in the sproc).
The idea is that you do not want to extend the boundaries of your
transaction outside of the server. By using
SqlConnection/SqlTransaction and passing separate commands inside of
an explicit transaction, you are multiplying the number of round trips
required by the number of commands you use if you go the
one-command-per-sproc route. Once you initiate a transaction, you are
holding exclusive locks on the resources involved for the duration of
that transaction, potentially blocking other processes attempting to
access the same data, and increasing the likelihood of deadlocks. This
applies to other processes that are only selecting data since SQL
Server's default isolation level of READ COMMITTED prevents data from
being read when it is locked.
--Mary
On Mon, 29 Aug 2005 09:15:17 -0700, Alex S Moore <Alex S
Moore@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>Using vb.net for code behind on a asp.net application.
>
>I need to run a number of sqlcommands, based on user input. The commands
>need to run as a single transaction. The commands are all stored procedures.
>
>How do I do this? I was thinking that I could build an array of the
>sqlcommands, but I do not see how to do it. I looked at arraylist, but still
>not sure.
>
>Maybe the question could be stated as:
>When I run a sqlcommand in a transaction, does the sqlcommand need to
>persist, or can I just reuse it to run another stored procedure within the
>same transaction?
.
- Follow-Ups:
- Re: transaction with unknown nbr of commands
- From: Alex S Moore
- Re: transaction with unknown nbr of commands
- References:
- transaction with unknown nbr of commands
- From: Alex S Moore
- transaction with unknown nbr of commands
- Prev by Date: Re: Auto update data on RowChanged
- Next by Date: Re: Auto update data on RowChanged
- Previous by thread: Re: transaction with unknown nbr of commands
- Next by thread: Re: transaction with unknown nbr of commands
- Index(es):
Relevant Pages
|