Solved

vb.net datareader and changing the isolation level

Posted on 2011-02-16
6
1,074 Views
Last Modified: 2012-05-11
can anyone provide some example code in VB.net on how to change the isolation level for a datareader. I know you can do this in the sql code but I dont want to do this.

thanks

Ian
0
Comment
Question by:alchemy9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34907581
You can add this in your select command

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

So, for example

dbcommand.CommandText = "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; Select * From tablename..."
0
 
LVL 9

Accepted Solution

by:
wellhole earned 500 total points
ID: 34907647
On your connection, you just have to start the transaction and set the isolation level.

conn.BeginTransaction(IsolationLevel.ReadUncommitted)
0
 

Author Comment

by:alchemy9
ID: 34908585
So is this code ok

Dim con As New SqlConnection
            con.ConnectionString = constring
            con.Open()

  mytransaction = con.BeginTransaction(IsolationLevel.ReadUncommitted)

 Dim sql As String = "select  top 100 * from a table"
        Dim com As New SqlCommand(sql, con)  
            com.Connection = con

 
 Dim dr As SqlDataReader = com.ExecuteReader()

   While dr.Read()

'process

   End While

dr.Close()
con.Close()
con.Dispose()
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:alchemy9
ID: 34908677
looking at the previous code, assuming its ok what about a comit is that needed?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34908716
This is a Select command so a transaction is not needed me thinks. Did you try my suggestion?
0
 
LVL 9

Expert Comment

by:wellhole
ID: 34908940
If you're not making any data changes, a commit is not necessary.
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

730 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