Solved

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

Posted on 2010-08-24
9
990 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 51

Expert Comment

by:Huseyin KAHRAMAN
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 51

Expert Comment

by:Huseyin KAHRAMAN
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Name Space error VS2015 1 37
Access Schema 6 45
VB.net VSTO Excel Ribbon error 4 13
Convert VB web project to C# 3 38
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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