473,386 Members | 1,705 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,386 software developers and data experts.

System.Transactions and database locking.

I've implemented transactions in my dotNet 2.0 project using
System.Transactions and TransactionScope.
---
TransactionOptions options = new TransactionOptions();
options.IsolationLevel = System.Transactions.IsolationLevel.Serializable;
options.Timeout = new TimeSpan(0, 5, 0);
using (TransactionScope transactionScope = new
TransactionScope(TransactionScopeOption.Required, options))
{
DoWork();
transactionScope.Complete(); //Tell the transaction to commit
}
---

When I debug this code and stop debugging inside the DoWork after it has
inserted some rows in some tables but before the transaction has completed,
selection database queries to the tables updated time out, (other users can
still run selects against the database). The selects run fine again when I
run the transaction to completion.

Is this because of my IsolationLevel.Serializable? And how do I avoid this
locking?

Is there some online documentation of isolation levels, that explains them
thoroughly?

Kind Regards,
Allan Ebdrup
Feb 12 '07 #1
8 10908
Summary is here:
http://msdn2.microsoft.com/en-us/lib...tionlevel.aspx

do you mean you are blocking yourself? normally ADO.Net commands
should enlist inside the ambiant transaction (if one), so presumably
one of the following is the problem:
* The connections are not compatible for enlisting - is it the same
user account?
* Are you explicitely creating a null (chaos) transaction scope around
the select?
* Do your select commands / connections perhaps exist before the
transaction scope?

TransactionScope works best when the connection pool is utilised and
commands are created on-demand, rather than existing for an age
independently (in which case they may struggle to enlist).

Serializable isolation can cause blocking; this is expected (but it
reduces conflicting data movement during transactions, improving
ACIDity); in my experience, "range" locks are the most unanticipated
ones. Serializable isolation can also (when used incorrectly) cause
deadlocks if 2 serializable connections read data then both attempt to
escalate to a write lock; this can be reduces by using (UPDLOCK) when
you read the data to take out an exclusive lock at the start, rather
than escalate to exclusive from read.

Marc
Feb 12 '07 #2
(chaos)
I possibly meant ReadUncommitted...
Feb 12 '07 #3
This is because the state of the MSDTC on the local machine is inconsistent
with you stopping debugging half way through a transaction.

If you stop and restart the MSDTC on the local machine everything will be
fine.

I wonder if this a bug in VS 2005 and\or System.Transaction namespace

HTH

Ollie Riches

"Allan Ebdrup" <eb****@noemail.noemailwrote in message
news:Oj*************@TK2MSFTNGP05.phx.gbl...
I've implemented transactions in my dotNet 2.0 project using
System.Transactions and TransactionScope.
---
TransactionOptions options = new TransactionOptions();
options.IsolationLevel = System.Transactions.IsolationLevel.Serializable;
options.Timeout = new TimeSpan(0, 5, 0);
using (TransactionScope transactionScope = new
TransactionScope(TransactionScopeOption.Required, options))
{
DoWork();
transactionScope.Complete(); //Tell the transaction to commit
}
---

When I debug this code and stop debugging inside the DoWork after it has
inserted some rows in some tables but before the transaction has
completed, selection database queries to the tables updated time out,
(other users can still run selects against the database). The selects run
fine again when I run the transaction to completion.

Is this because of my IsolationLevel.Serializable? And how do I avoid this
locking?

Is there some online documentation of isolation levels, that explains them
thoroughly?

Kind Regards,
Allan Ebdrup

Feb 12 '07 #4
"Ollie Riches" <ol**********@hotmail.comwrote in message
news:u7**************@TK2MSFTNGP02.phx.gbl...
This is because the state of the MSDTC on the local machine is
inconsistent with you stopping debugging half way through a transaction.

If you stop and restart the MSDTC on the local machine everything will be
fine.

I wonder if this a bug in VS 2005 and\or System.Transaction namespace
So it's only a problem when debugging? My concern is that selects are
blocked while the transaction is in progress, will this not happen in
production when I'm not running in debug mode?

Kind Regards,
Allan Ebdrup.
Feb 14 '07 #5
Yes it will only happen when debugging from VS, it won't happen in
production

HTH

Ollie Riches

"Allan Ebdrup" <eb****@noemail.noemailwrote in message
news:%2******************@TK2MSFTNGP03.phx.gbl...
"Ollie Riches" <ol**********@hotmail.comwrote in message
news:u7**************@TK2MSFTNGP02.phx.gbl...
>This is because the state of the MSDTC on the local machine is
inconsistent with you stopping debugging half way through a transaction.

If you stop and restart the MSDTC on the local machine everything will be
fine.

I wonder if this a bug in VS 2005 and\or System.Transaction namespace

So it's only a problem when debugging? My concern is that selects are
blocked while the transaction is in progress, will this not happen in
production when I'm not running in debug mode?

Kind Regards,
Allan Ebdrup.

Feb 14 '07 #6
"Marc Gravell" <ma**********@gmail.comwrote in message
news:ev**************@TK2MSFTNGP02.phx.gbl...
Summary is here:
http://msdn2.microsoft.com/en-us/lib...tionlevel.aspx

do you mean you are blocking yourself?
I'm running the transaction in debug mode in VS2005 and pausing inside the
transaction, when I connect to the database using the Query Analyzer,
selects form the tables touched by the transaction simply time out and never
complete. Users on other machinces can still connect to the database and run
the queries that time out for me. When I run the transaction to completion
everything is back to normal.

I can't see how a transaction could ever cause selects of tables involved in
the transaction to time out, the transaction should be atomic so I don't see
it's updates until it completes, but I can't see how it should cause selects
not to run while the transaction is in progress.

Kind Regards,
Allan Ebdrup
Feb 14 '07 #7
when doing a selct using the 'with' keyword as in:

Select * from Order with(nolock)

Sql Server can choose to ignore the 'with' keyword.

HTH

Ollie Riches

"Allan Ebdrup" <eb****@noemail.noemailwrote in message
news:e2*************@TK2MSFTNGP06.phx.gbl...
"Marc Gravell" <ma**********@gmail.comwrote in message
news:ev**************@TK2MSFTNGP02.phx.gbl...
>Summary is here:
http://msdn2.microsoft.com/en-us/lib...tionlevel.aspx

do you mean you are blocking yourself?

I'm running the transaction in debug mode in VS2005 and pausing inside the
transaction, when I connect to the database using the Query Analyzer,
selects form the tables touched by the transaction simply time out and
never complete. Users on other machinces can still connect to the database
and run the queries that time out for me. When I run the transaction to
completion everything is back to normal.

I can't see how a transaction could ever cause selects of tables involved
in the transaction to time out, the transaction should be atomic so I
don't see it's updates until it completes, but I can't see how it should
cause selects not to run while the transaction is in progress.

Kind Regards,
Allan Ebdrup

Feb 14 '07 #8
"Atomic" is only one part of ACID; "Isolated" is also a key one. That
means that another client should not be adversely affected by you...

Scenario: your transaction is open, and you have manipulated data;
somebody else wants to read that data (or a "range" that you impacted,
etc)... three options:
1: wait for your transaction to end, and then read the data in its
final form
2: return your original changes
3: return your as yet uncommitted changes

"NOLOCK" and low isolation levels work using option 3; this has the
unfortunate side-effect that if you rollback your change, they have a
copy of data *that never existed*. Whoops! Serializable works using 1,
which protects you from dirty / non-repeatable reads, but does it by
queuing competing access. Different callers with different isolations
will see different versions of the truth.

There are many scenarios eto cover the permutations of read/write
versus read/write.

Marc
Feb 14 '07 #9

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

Similar topics

0
by: Heikki Tuuri | last post by:
Hi! Many people have complained over years that Borland's dbExpress driver does not work with MySQL and transactions, because it disconnects from mysqld after each SQL statement. The postings...
0
by: Chris Travers | last post by:
Hi All; I may be able to do this in Perl, but if there is enough interest in doing something like this in C, maybe I can still help (however, consider your self warned about my skill at coding...
7
by: JS | last post by:
Can somebody explain how to get the tablespace out of quiesce mode? I am executing on each node of my EEE Win2K system: db2 quiesece tablespace for table schema.tablename RESET I get the...
9
by: TD | last post by:
I am trying to add transactions to my code. The original code worked fine until I followed an example to setup transactions, now the code does strange things, but no error messages. Could...
3
by: Ace Calhoon | last post by:
Hello, I have a VBA/Database application which reads files, analyzes them, updates a database, and then moves them to an archive. I would like to make this an atomic transaction -- that is, if...
11
by: Mike P | last post by:
I've been using C# transactions for a while and had no problems with them. Using try catch blocks I can trap basically all possible errors and rollback all necessary data. Over the last few...
3
by: Brian Foree | last post by:
I am developing an ASP.NET application that uses Access 2000 as its backend, and have just started getting the following error on 2 ASP.NET pages that had been working until late last week (and I...
0
by: Marco Castro | last post by:
Im trying to create a system service that will read some records within an access file. From these values I will then be able to see if other software in the system is up to date and install the...
1
by: RAM | last post by:
Hello, I am learning .NET 2.0 (ASP.NET, ADO.NET). I would like to ask experienced programmers when to use System.Transactions. One programmer told me that he never used System.Transactions, he...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.