Rogelio wrote:
The point is the following, I did a test with SQL Server and two Query Analyzer instances (two connections).
-
Connection 1 with a transaction updating a record and a wait of ten seconds before
the commit. Isolation Read Commited.
-
Connection 2 with a Select of the record being updating by Connection 1.
As soon as I started the batch of Connection 1 and started the batch of Connection 2, the
10 seconds of Conn. 1 gave me the time to start the second one.
With the SQL server default of Read Commited, the second connection got locked until
Conn. 1 finished. Then I add a set isolation level to read uncommited to the second conn., before the Select statement. The results were different, conn. 2 finished before conn. 1, with the data changed by conn. 1.
True, a transaction places X locks on the rows affected which lock out any reader of another connection till the X locks are removed.
As I am developing multi-user application, I do not want a transaction changing records,
locks my other users that are reading only.
I was thinking may be you can change the logic of the DataAdapter to change the
isolation level to the one that is specificied in it; but only when the isolation level is
not the default and there is not transaction active. Something like:
Set Isolation "the one specificied in isolationlevel property"
Select ..........
If you don't want a transaction to lock out other users, create the transaction with the ReadUncommitted isolation level, for example:
adapter.StartTransaction(...)
// do things here, also recursive saves
adapter.Commit();
this will make sure your transaction won't lock out readers. Though this shouldn't be necessary: row changes/deletes should be done at the end of a routine so the changes can be pushed to the database and the time readers are locked out is minimized. I mean by this that should avoid starting a transaction, do a lot of reading, open forms wait for user input etc. etc. and after that committing it. Transactions should be started right before some activity on the database has to be performed and should be closed right after that and reads should preferably be done outside the transaction.