vb.net datareader and changing the isolation level

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
alchemy9Asked:
Who is Participating?
 
wellholeConnect With a Mentor Commented:
On your connection, you just have to start the transaction and set the isolation level.

conn.BeginTransaction(IsolationLevel.ReadUncommitted)
0
 
CodeCruiserCommented:
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
 
alchemy9Author Commented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
alchemy9Author Commented:
looking at the previous code, assuming its ok what about a comit is that needed?
0
 
CodeCruiserCommented:
This is a Select command so a transaction is not needed me thinks. Did you try my suggestion?
0
 
wellholeCommented:
If you're not making any data changes, a commit is not necessary.
0
All Courses

From novice to tech pro — start learning today.