Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top