Results 1 to 6 of 6

Thread: [RESOLVED] ASP.Net Database Error Problem

  1. #1

    Thread Starter
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Resolved [RESOLVED] ASP.Net Database Error Problem

    I have a web application which integrates with a remote sql server database.

    In general the application works fine however at least once a day if someone is using the system they will receive the following error:

    ExecuteReader requires an open and available Connection. The connection's current state is Closed.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.InvalidOperationException: ExecuteReader requires an open and available Connection. The connection's current state is Closed.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:


    [InvalidOperationException: ExecuteReader requires an open and available Connection. The connection's current state is Closed.]
    System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean executing) +279
    System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +80
    System.Data.SqlClient.SqlCommand.ExecuteReader() +42
    Repairs.WebDBTools.LoadControl(ListBox& p_lstBox, String p_sqlstmt)
    Repairs.ReceiveProduct.Page_Load(Object sender, EventArgs e)
    System.Web.UI.Control.OnLoad(EventArgs e) +67
    System.Web.UI.Control.LoadRecursive() +35
    System.Web.UI.Page.ProcessRequestMain() +731
    --------------------------------------------------------------------------------
    Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
    i know above it shows the method that has the problem but this happens with any function i have that tries to access the database

    the way in which my application works is that it creates an instance of the database connection for each session that accesses the site

    i have no idea what is causing the error, at first i presumed it was some shared methods but after changed these to instance methods users still get the same error.

    In order to fix the issue i've to restart IIS on our server so as to refresh everything.


    Has anyone got any ideas to what could be the problem
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

  2. #2
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: ASP.Net Database Error Problem

    So you have a database connection open across a Session?

    I was going to say the connection sounds dodgy but if you have the connection open across the session then it might be performance issues causing this.

    Ever thought of having local database connections?

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

  3. #3

    Thread Starter
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Re: ASP.Net Database Error Problem

    the remote database is not one i've created but its one that im required in the project to retrieve and update data to. so this database will never be local for me. while my web application must remain local.

    Would you recommend putting a timeout on the sessions so at least the connection will be closed after X amount of time and the session will then need to re-establish the connection again.

    Or do sessions have an automatic timeout or do they stay active even after the browser has been closed.

    Several users can access the site fine and update/retrieve data from the remote sql server database.

    however once this error appears for one person all users will receive the error, this is why i dont know if it session related
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

  4. #4
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: ASP.Net Database Error Problem

    No you misunderstand me.

    I don't think opening a database connection in the Session object is very efficient. If you have a large amount of traffic on the site then you could get problems like dropped connections - not because of the Session but because of the large numbers of open database connections.

    When I said local database connection I meant opening the connection just before you need it and closing it just after.

    How many people use your site?

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

  5. #5

    Thread Starter
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Re: ASP.Net Database Error Problem

    there ll be a max of 6 people ever using the site at the one time, its for and intranet
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

  6. #6

    Thread Starter
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    Re: ASP.Net Database Error Problem

    the code will explain the way i have it:

    VB Code:
    1. Imports System.Data.SqlClient
    2.  
    3. Public Class WebConn
    4.     ' singleton that maintains a connection to the database
    5.  
    6.     Private Shared theInstance As WebConn
    7.     Private m_connection As SqlConnection
    8.  
    9.     Public ReadOnly Property connection() As SqlConnection
    10.         Get
    11.             Return m_connection
    12.         End Get
    13.     End Property
    14.  
    15.     Public Shared Function getInstance() As WebConn
    16.         If theInstance Is Nothing Then
    17.             theInstance = New WebConn
    18.         End If
    19.         Return theInstance
    20.     End Function
    21.  
    22.     Public Sub New()
    23.         'Create an Connection object,
    24.         'and then pass in the ConnectionString to the constructor.
    25.         m_connection = New SqlConnection(ApplicationSettings.SQL_SERVER_CONNECTIONSTRING)
    26.         Try
    27.             m_connection.Open()
    28.         Catch ex As Exception
    29.             Throw New Exception("Unable to establish connection to web")
    30.         End Try
    31.  
    32.     End Sub
    33.  
    34.     Protected Overrides Sub finalize()
    35.         Try
    36.             'm_connection.Close()
    37.         Catch ex As Exception
    38.  
    39.         End Try
    40.  
    41.  
    42.     End Sub
    43.  
    44. End Class


    so everytime i want to execute some database code i just called the webconn.getconnection() method which checks if the connection exists, if not creating one
    Last edited by Strider; May 17th, 2005 at 08:13 AM.
    Barry


    Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
    .NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0

    SQL Server 2005/2000/SQL Server CE 2.0


    If you like, rate this post

    Compact Framework for Beginners

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width