Solved

vb.net datareader and changing the isolation level

Posted on 2011-02-16
6
1,061 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

943 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

5 Experts available now in Live!

Get 1:1 Help Now