Solved

vb.net datareader and changing the isolation level

Posted on 2011-02-16
6
1,058 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

16 Experts available now in Live!

Get 1:1 Help Now