Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.Net / VB.Net - Issue with datareader If dr.read throwing object instance errors?

Posted on 2010-08-24
9
Medium Priority
?
1,001 Views
Last Modified: 2012-05-10
Hello all,

I have an application that on one of our servers for some reason randomly I am getting errors on any of my datareaders that I do a "If dr.read".  Here is a sample error: and then I will show my code which should be fine I think:  This is running on IIS 7 which seems to be having more issues.  The code I beleive is okay.

Event log error sample:
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 8/24/2010 10:37:48 PM
Event time (UTC): 8/25/2010 2:37:48 AM
Event ID: dd178c4f307f4ae483593abb4b67a5b6
Event sequence: 304
Event occurrence: 3
Event detail code: 0
 
Application information:
    Application domain: /LM/W3SVC/2/ROOT/SGINET-1-129271770825172621
    Trust level: Full
    Application Virtual Path: /SGINET
    Application Path: E:\SGIKBWebsite\SGINET\
    Machine name: SGI-KB2
 
Process information:
    Process ID: 2836
    Process name: w3wp.exe
    Account name: IIS APPPOOL\SGINET
 
Exception information:
    Exception type: NullReferenceException
    Exception message: Object reference not set to an instance of an object.
 
Request information:
    Request URL: http://sginet:8088/SGINET/contactdet.aspx?av_id=207342116&salesman=HA&buyer=null&page='avail' 
    Request path: /SGINET/contactdet.aspx
    User host address: XXXXXXXXX
    User:  
    Is authenticated: False
    Authentication Type:  
    Thread account name: IIS APPPOOL\SGINET
 
Thread information:
    Thread ID: 6
    Thread account name: IIS APPPOOL\SGINET
    Is impersonating: False
    Stack trace:    at SGNETCODE.contactdet.Page_Load(Object sender, EventArgs e) in C:\Applications\LatestVersions\SGI\SGINET\SGI_SourceCode_V29\SGNETCODE_20100125\contactdet.aspx.vb:line 48
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Code:

On the top (just taking snippets here not all code):

Imports System.Data
Imports System.Data.SqlClient
    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

    Dim dr As SqlDataReader

Then in the page load simply:

dr = objvalidate.executereader(strsql)
                If dr.Read() Then

bombs on the above if dr.read() line.  This is happening randomly on lots of areas of the site for some reason.  Any ideas?
0
Comment
Question by:sbornstein2
[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
9 Comments
 
LVL 60

Expert Comment

by:HainKurt
ID: 33517831
maybe your issue is this

Only one SqlDataReader per associated SqlConnection may be open at a time, and any attempt to open another will fail until the first one is closed. Similarly, while the SqlDataReader is being used, the associated SqlConnection is busy serving it until you call Close.

are you closing the readers all the time after you consume it?
0
 
LVL 60

Expert Comment

by:HainKurt
ID: 33517842
also can you please post the code for

objvalidate.executereader(strsql)

function...
0
 

Expert Comment

by:nuijang24
ID: 33518226
when usability sqlDatareader. Are you sure connection database not closed.
maybe you can use HasRows method for check data in object sqlreader
 if dr.HasRows then
   dr.read()
...
 
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:sbornstein2
ID: 33518292
No its just random, same type error here on the while dr.read line.

  dr.Close()
        dr = objvalidate.FetchAdditionalContact(showcoid)
        While dr.Read
' errors on the above line.

The Fetch call is this:

  Public Function FetchAdditionalContact(ByVal CoID As String) As Object
        cmdvalidate = New SqlCommand("spFetchAdditionalContacts", sqlcon)
        cmdvalidate.CommandType = CommandType.StoredProcedure
        cmdvalidate.Parameters.Add(New SqlParameter("@coid", SqlDbType.VarChar, 6))
        cmdvalidate.Parameters("@coid").Value = CoID
        If sqlcon.State = ConnectionState.Open Then
            sqlcon.Close()
        End If
        Try
            sqlcon.Open()
            dr = cmdvalidate.ExecuteReader(CommandBehavior.CloseConnection)
            FetchAdditionalContact = dr
        Catch ex As Exception
            sqlcon.Close()
        End Try
    End Function

The thing is these issues did not come up in IIS 6.  Its so odd, I had to set the LoadUserProfile = true in IIS 7 to even get the site to work.  IIS 7 sucks lol
0
 
LVL 9

Expert Comment

by:puru1981
ID: 33518627
programatically you are doing very wrong thing.

I hope sqlcon is a shared connection between the class or global. You are closing the connection if connectionstate is open without thinking that somewhere the datareader will be using it to fetch data from database. I am not sure if you are closing the datareader. For this reason when connection is closed from some other process the error is obvious. i don't think it has to do something with IIS7. if you want to work this way then open the connection fetch the data using dataadapter and datatable.
0
 
LVL 14

Accepted Solution

by:
raja_ind82 earned 2000 total points
ID: 33519974
0
 

Author Comment

by:sbornstein2
ID: 33525399
puru how do you figure the datareader will be using the connection after it is already loaded from the executereader command and then closed in the function.  The datareader is then passed along and then used.
0
 

Author Comment

by:sbornstein2
ID: 33542456
It is getting a Timeout expired or server cant connect error along those lines.  I am leaning towards they are now on VMWare and there must be packet loss going on with the SQL Server because it is totally random.  I also placed a long timeout on the commands but still same error.  I am going to try some thing with connection pooling etc. but think there is a routing issue going on.
0
 

Author Closing Comment

by:sbornstein2
ID: 33579813
it was in the URLs thanks
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

604 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