Solved

SQL 2005 Transcation : is .net transaction default to read commited?is this why can't read from table where insert is done until commit?

Posted on 2013-05-30
2
412 Views
Last Modified: 2013-06-01
I set up a .net transcation where I inserted into Table1
then Updated Table2, then commited.

Immediately after the insert was done into Table1 (before the commit), I could not read from Table1 - it was locked for reading any record until commit/rollback.

Is this because the default .net isolation level is "READ COMMITTED"?
Will READ COMMITTED cause this behaviour?

Now because of this I did the transaction in a SQL Stored Proc.
The default behaviour is different here - I can read after the Insert , and before the commit.
What is the default isolation level then for SQL Server 2005? Same/Different than .net? Can anyone comment on this please?

E.g.
 USE AdventureWorks
 BEGIN TRAN
Insert into Person.Address(AddressLine1,City,StateProvinceID,PostalCode,rowguid,ModifiedDate¿¿) select '1973 Napa Ct.','Bothell',79,'98011','9AADCB0D-36CF-483F-84D8-585C2D4EC6E3',getdate()

select * from Person.Address

ROLLBACK
0
Comment
Question by:jxharding
2 Comments
 
LVL 20

Accepted Solution

by:
Marten Rune earned 500 total points
ID: 39210135
This is why. Either use isolation level read uncommitted, or use the hint in the Querys: With NOLOCK
As select * from table tblMyTable WITH (NOLOCK) where bla bla.
There is also the option to alter database set snapshot isolation mode on, then you can use the snapshot isolation, wich basically prevents locks by keeping a snapshot of the data so it Always presents transactionally consistent data to the Querys.

Ragards Marten
0
 

Author Closing Comment

by:jxharding
ID: 39212803
Thanks, I can't figure out yet why, even though I did not indicate in the SQL Server Proc any change to the default isolation level (read committed) - I still can read from the table before I commit. After I rollback then, the rows which I just viewed are gone.

Is there a way to, in the middle of a transaction, view the isolation level perhaps? I dont think one can set the default isolation level on a DB? Yet somehow this happens without setting the isolation level to read uncommitted
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now