Solved

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

Posted on 2010-08-24
9
983 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
9 Comments
 
LVL 51

Expert Comment

by:HainKurt
Comment Utility
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:HainKurt
Comment Utility
also can you please post the code for

objvalidate.executereader(strsql)

function...
0
 

Expert Comment

by:nuijang24
Comment Utility
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
 

Author Comment

by:sbornstein2
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 9

Expert Comment

by:puru1981
Comment Utility
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
Comment Utility
0
 

Author Comment

by:sbornstein2
Comment Utility
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
Comment Utility
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
Comment Utility
it was in the URLs thanks
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

10 Experts available now in Live!

Get 1:1 Help Now