469,600 Members | 2,218 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,600 developers. It's quick & easy.

Connection Pooling Problem?

Bob
I have an ASP.NET web application that has been running without any problems for a while. I recently transferred the site to shared hosting and had multiple users start to use the site. The problem I'm experiencing is that when many users are hitting the site at once, occasionaly I will see errors. The 3 most common ones are: "The SqlCommand is currently busy Open, Fetching. ", "Internal Connection Fatal Error", "object reference not set to an instance of an object"

In addition, occassionally the application will lockup for hours after one of these errors. I can navigate to pages, but I cannot log in to my application - I get a "request timed out" error. It usually seems to go away after a few hours - but obviosuly this is very weird behavior

The research I have done so far indicates that the "The SqlCommand is currently busy Open, Fetching." error usually occurs because a connection that was not properly closed is returned to the connection pool or is accessed when it is still outside the pool (and open) because multiple users are hitting it at the same time. The article I've seen about this (http://www.experts-exchange.com/Prog..._20942137.html) mentioned someone putting his data access components in a module, and the accepted solution was to put everything in a class.

However, the Data Access Layer design I'm using has worked in several other multi-user web applications, so it is odd that this is happening. I am using InProcess session state, and other than that I don't know what other configuration setting might be affecting this. Could this be an IIS or hardware configuration problem? It is impossible to replicate this in debug mode because it only happens when multiple users hit the system. Anyway, thanks in advance for the help

Here is one of the methods where the "SqlCommand is currently busy Open, Fetching" error occurred

public void GetAllRestaurantsByGroup(RestaurantCollection col, int groupid

tr

Connect()

PrepareCommand("Restaurant_Select_All_By_Group")
m_dsoCommand.AddParameters("@group_id", groupid)
return m_dsoCommand.ExecuteReader()
while (m_sqlReader.Read()

Restaurant oRestaurant = new Restaurant()
oRestaurant.RestaurantName = (string)m_sqlReader["restaurantname"]
oRestaurant.GroupID = (int)m_sqlReader["groupid"]
oRestaurant.LastVisit = (System.DateTime)m_sqlReader["lastvisit"]
oRestaurant.Description = (string)m_sqlReader["description"]
oRestaurant.Distance = (double)m_sqlReader["distance"]
oRestaurant.MapURL = (string)m_sqlReader["MapURL"]
oRestaurant.DBBacked = true
col.Add(oRestaurant)
catch(Exception e

throw e
}
finall

Disconnect()

The code called by this method is below

protected DSOConnection m_dsoConnection
protected SqlDataReader m_sqlReader

public void Connect(

tr

m_dsoConnection.Open()
catch(Exception e

throw e

public void Disconnect(

tr

if (m_sqlReader != null && !m_sqlReader.IsClosed

m_sqlReader.Close()
m_dsoConnection.Close()
catch(SqlException e

throw e

protected virtual void PrepareCommand(string sStoredProcedure

tr

m_dsoCommand.CommandText = sStoredProcedure
m_dsoCommand.Connection = m_dsoConnection.Connection
m_dsoCommand.CommandType = CommandType.StoredProcedure
m_dsoCommand.ClearParameters()

catch(Exception exp

throw exp

Finally, my custom DSOConnection and DSOCommand classes are defined below

public class DSOConnectio

#region field

private string m_connectionString = null;
private SqlConnection m_connection = null;

#endregion

#region properties
public SqlConnection Connection
{
get
{
return m_connection;
}
}

#endregion

#region methods
#region construction/destruction
public DSOConnection(string connection)
{
m_connectionString = connection;
m_connection = new SqlConnection(m_connectionString);
}

#endregion

#region open/close
public void Open()
{
try
{
if(m_connection.State!=ConnectionState.Open)
{
m_connection.Open();
}
}
catch(Exception e)
{
throw e;
}
}

public void Close()
{
try
{
if(m_connection.State!=ConnectionState.Closed)
{
m_connection.Close();
}

}
catch(SqlException e)
{
throw e;
}
}
#endregion

#endregion
}

public class DSOCommand
{
#region fields

private SqlCommand m_sqlcommand = null;

#endregion

#region constructors

public DSOCommand()
{
m_sqlcommand = new SqlCommand();
}//End of DSOCommand constructor
#endregion

#region Properties

public int CommandTimeOut
{
get
{
return m_sqlcommand.CommandTimeout;
}
set
{
m_sqlcommand.CommandTimeout = value;
}
}

public string CommandText
{
get
{
return m_sqlcommand.CommandText;
}
set
{
m_sqlcommand.CommandText = value;
}
}
public SqlConnection Connection
{
get
{
return m_sqlcommand.Connection;
}
set
{
m_sqlcommand.Connection = value;
}
}

public CommandType CommandType
{
get
{
return m_sqlcommand.CommandType;
}
set
{
m_sqlcommand.CommandType = value;
}
}

public SqlParameterCollection Parameters
{
get
{
return m_sqlcommand.Parameters;
}
}//End of CommandType

#endregion

#region methods

public void ClearParameters()
{
m_sqlcommand.Parameters.Clear();
}//End of ClearParameters

public void AddParameters(string sParameterName, object oValue)
{
if(oValue != null)
{
m_sqlcommand.Parameters.Add(sParameterName,oValue) ;
}
else
{
m_sqlcommand.Parameters.Add(sParameterName,DBNull. Value);
}
}//End of AddParameters

public void AddParameters(string sParameterName, object oValue, ParameterDirection pdir)
{
SqlParameter p = new SqlParameter(sParameterName, oValue);
p.Direction = pdir;

if(oValue != null)
{
m_sqlcommand.Parameters.Add(p);
}
else
{
p.Value = DBNull.Value;
m_sqlcommand.Parameters.Add(p);
}

}//End of AddParameters

public SqlDataReader ExecuteReader()
{
return m_sqlcommand.ExecuteReader();
}//End of ExecuteReader

public int ExecuteNonQuery()
{
return m_sqlcommand.ExecuteNonQuery();
}//End of ExecuteNonQuery

#endregion
}
I have also included the full text of the error below:
Server Error in '/' Application.

--------------------------------------------------------------------------------

The SqlCommand is currently busy Open, Fetching.
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: The SqlCommand is currently busy Open, Fetching.

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: The SqlCommand is currently busy Open, Fetching.]
LunchinatorBusinessLayer.Data.Manager.RestaurantMa nagerDSO.GetAllRestaurantsByGroup(RestaurantCollec tion col, Int32 groupid) in C:\Documents and Settings\Bob\My Documents\Visual Studio Projects\Lunchinator\LunchinatorBusinessLayer\Data \Manager\RestaurantManagerDSO.cs:266
LunchinatorBusinessLayer.Business.Collection.Resta urantCollection.GetAllRestaurantsByGroup(Int32 groupid) in C:\Documents and Settings\Bob\My Documents\Visual Studio Projects\Lunchinator\LunchinatorBusinessLayer\Busi ness\Collection\RestaurantCollection.cs:67
Lunchinator.Main.Results.SetMostVotes() in c:\inetpub\wwwroot\Lunchinator\Main\Results.aspx.c s:92
Lunchinator.Main.Results.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\Lunchinator\Main\Results.aspx.c s:68
System.EventHandler.Invoke(Object sender, EventArgs e) +0
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

Jul 21 '05 #1
0 5118

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by John | last post: by
1 post views Thread by Mark | last post: by
6 posts views Thread by Chris Szabo | last post: by
1 post views Thread by Lenny Shprekher | last post: by
3 posts views Thread by Martin B | last post: by
3 posts views Thread by howachen | last post: by
16 posts views Thread by crbd98 | last post: by
20 posts views Thread by fniles | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.