0

I begin a transaction with SqlConnection.BeginTransaction() and I do a DELETE and some INSERTs. There is any configuration I can do on the isolation level to allow any query to read the data on a "dirty way" during the transaction?

Basically I want to prevent locks while I update the data. The problem is; I can't control the SELECTs. If I define a ReadUncommited isolation level on my transaction will the external querys have rights to read the data without waiting or is required to define it on this querys?

For example:

try
{                         
   connection.Open();
   transaction=connection.BeginTransaction(IsolationLevel.ReadUncommited);            

   // DELETE
   foreach (int i in fibarray)
   {
       // INSERTS
   }
   transaction.Commit();
}
catch (Exception ex)
{
   if (transaction.Connection != null)
       transaction.Rollback();
}             

Meanwhile, the SELECTS on another machine I have not the access.

SysDragon
  • 9,692
  • 15
  • 60
  • 89
  • Each connection/session establishes for itself what level of dirtiness it's willing to put up with. There's no way for a *different* connection to suddenly force a connection to see dirtier data (or, conversely, to be more strict) – Damien_The_Unbeliever Dec 18 '13 at 13:33
  • @Damien_The_Unbeliever So there is no way to tell my update commands not to block. It depends entirely on the "`SELECT`s" side. – SysDragon Dec 18 '13 at 14:38
  • Yes, the `SELECT`s have all of the control over their locking/blocking behaviour. And `UPDATE`s always have to apply some exclusive locks to complete successfully. – Damien_The_Unbeliever Dec 18 '13 at 14:47
  • @Damien_The_Unbeliever Well, that was the information I was asking for, so if you don't mind add it as an answer. – SysDragon Dec 18 '13 at 14:55

2 Answers2

2

Each connection/session establishes for itself what level of dirtiness it's willing to put up with. There's no way for a different connection to suddenly force a connection to see dirtier data (or, conversely, to be more strict)

The SELECTs have all of the control over their own locking/blocking behaviour. And UPDATEs always have to apply some exclusive locks to complete successfully. So if you cannot change the SELECTs, then you can't overcome your current situation.

Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
0

Try WITH(NOLOCK) clause on the other SELECTS. This clause will read dirty data.

Example

SELECT ....
FROM <tablename> WITH(NOLOCK) 
WHERE ......

More info here

EDIT: BTW, setting the isolation level ReadUncommited will make the current transaction read uncommitted data, it doesn't control the isolation level of transactions of of the current scope.

Community
  • 1
  • 1