Click here to Skip to main content
15,913,773 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I am back with one more problem today.

I have ADO.NET application which inserts data to table. (ex Invoices)

I have written Transaction with IsolationLevel.ReadUncommitted in my ADO.net Application using c# code

Whenever i run this application and try to select data from my Invoices table, i am not able to do so.

ex:
When i fire below query from my sql query window when ADO.net Application is running,
Below query works,
select * from Invoices with(nolock,nowait)

Below query does not work,
select * from invoices

I know that when we use with(nolock,nowait) we can read uncommitted data, but i want to read only committed data, but it seems that the transaction is putting lock on my table and not allowing me to read any data.

I want to read only committed data.

What I have tried:

I Tried IsolationLevel.ReadCommitted,IsolationLevel.ReadUnCommitted in my ado.net Application


Please suggest what can be done in this situation.
Posted
Updated 25-Aug-16 1:57am
v2

1 solution

OK, so the subject of SQL Server Isolation levels is quite a tricky one to get to grips with.
Now to address your question specifically, your SELECT statement cannot complete because it needs to read ALL records in the table and as the INSERT statement is still inserting records, the select cannot finish reading the table until after the insert completes.

Now let us suppose you are happy for your SELECT statement to ignore rows that are currently locked (i.e. those being inserted). You could use the READPAST query hint in order to permit your select statement to finish whilst the Insert statement is running.

SELECT * FROM TableName WTIH(READPAST)
Make sense?
 
Share this answer
 
Comments
sunil mali 27-Aug-16 5:55am    
I dont want to use ReadPast as, i have to change my entire website queries.
Is there any way or Transaction Isolation Level using which i can enable select when insert is happening?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900