Solved

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

Posted on 2010-08-24
9
985 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
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: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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
imap mails 1 23
Please explain the parts of these 2 LINQ expressions 3 32
vb.net 1 month apart 11 30
VB.net capture  result of a SQL query in variables 3 11
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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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