Solved

vb.net datareader and changing the isolation level

Posted on 2011-02-16
6
1,068 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
  • 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

829 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