all groups > sql server programming > january 2006 >
You're in the

sql server programming

group:

Transaction question


Transaction question Kevin Yu
1/17/2006 10:18:52 PM
sql server programming: hi all,

got a question, what's the different of .NET transaction ( using connection
transaction ) and the transaction inside a store procedure?

which is faster? does .net transaction use DTC? or both use DTC?


thx

Kevin


Re: Transaction question Brian Selzer
1/18/2006 12:40:48 AM
There really isn't any difference. (See BEGIN DISTRIBUTED TRANSACTION in
BOL.) I contend, however, that transaction control should usually be
handled inside stored procedures.

Transactions should be as short as possible; therefore, you should wait
until the last possible instant before starting a transaction, and you
should commit as soon as possible. Cursors and long-running calculations
should be avoided within transactions. I use optimistic concurrency control
whenever possible, and use rowversions to determine whether a collision has
occurred. For most applications, the overall impact on performance of
resubmitting a tiny percentage of transactions due to collisions is
infinitely smaller than the impact of the additional blocking and the
increased probability of deadlocks that are inherent in pessimistic
concurrency control.

Obviously, starting a transaction on the connection makes it much more
difficult to minimize the duration of a transaction.



[quoted text, click to view]

Re: Transaction question Kevin Yu
1/18/2006 9:41:33 AM

[quoted text, click to view]

is there any resource on the net that I can have a complete comparision of
all those
concurrency control and how they are done?

thx Brian



For most applications, the overall impact on performance of
[quoted text, click to view]

Re: Transaction question Brian Selzer
1/19/2006 12:21:43 AM
Sorry, I don't know of a resource off hand.

For optimistic concurrency, the main difficulty is in verifying that nothing
has changed between the time that the procedure starts and the time that the
transaction is ready to be applied. You need to obtain the maximum
rowversions from the set of rows from each table that used in the
calculations, and you also need to know how many source rows were used from
each table. Any change that modifies or adds an interesting row will cause
the maximum rowversion to increase. Thus if the maximum rowversion is
different, that means that an insert or update occurred, or that the row
with the maximum rowversion was deleted. To detect deletes within a range
or rows, you use the count. If fewer rows exist, then a delete occurred.
Some people use WITH(NOLOCK) before the transaction, but I prefer WITH(READ
COMMITTED) instead, because you don't have to worry about another
transaction rolling back between the time that the procedure starts and the
time that the transaction is ready to be applied. In addition, strange
errors can occur if the row that is currently being read WITH(NOLOCK) is
changed between the index seek and the reading of the row.



[quoted text, click to view]

AddThis Social Bookmark Button