Hello, I'm having an issue with my Connection Pool being max. The error I'm receiving is:
Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. All pooled connections were in use and max pool size was reached.
I did some research on google and found that I may not be closing my connections properly. Could someone please look at my code and let me know if this correct or could be done better.
Here is my code that makes the connection and populates the SqlDataReader:
---------------------------------------------------------
public SqlDataReader GetAllStatusTypes()
{
SqlConnection statConn = new SqlConnection(GetConn());
SqlCommand statCmd = new SqlCommand("GetAllStatusTypes", statConn);
statCmd.CommandType = CommandType.StoredProcedure;
statConn.Open();
SqlDataReader drStat = statCmd.ExecuteReader(CommandBehavior.CloseConnection);
return drStat;
}
-----------------------------------------------------------
Here is the method receiving the SqlDataReader:
public void LoadStatusTypes()
{
SqlDataReader drStatus;
drStatus = stat.GetAllStatusTypes();
//int index = 0;
while (drStatus.Read())
{
ListItem newListItem = new ListItem();
newListItem.Value = drStatus.GetValue(0).ToString();
newListItem.Text = drStatus.GetValue(1).ToString();
cboStatusTypes.Items.Add(newListItem);
if (drStatus["StatusTypeID"].ToString() == stat.StatusTypeID.ToString())
{
cboStatusTypes.SelectedValue = drStatus["StatusTypeID"].ToString();
}
}
drStatus.Close();
}
-----------------------------------------------------------
I cannot close the drStat in GetAllStatusTypes because then I will not be able to return it.
When I create the SqlDataReader drStatus to except the passed SqlDataReader object I close that one. Will this also close the one being passed?
Any help would be very appreciated.
Thank you,
WebGuytoo
Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. All pooled connections were in use and max pool size was reached.
I did some research on google and found that I may not be closing my connections properly. Could someone please look at my code and let me know if this correct or could be done better.
Here is my code that makes the connection and populates the SqlDataReader:
---------------------------------------------------------
public SqlDataReader GetAllStatusTypes()
{
SqlConnection statConn = new SqlConnection(GetConn());
SqlCommand statCmd = new SqlCommand("GetAllStatusTypes", statConn);
statCmd.CommandType = CommandType.StoredProcedure;
statConn.Open();
SqlDataReader drStat = statCmd.ExecuteReader(CommandBehavior.CloseConnection);
return drStat;
}
-----------------------------------------------------------
Here is the method receiving the SqlDataReader:
public void LoadStatusTypes()
{
SqlDataReader drStatus;
drStatus = stat.GetAllStatusTypes();
//int index = 0;
while (drStatus.Read())
{
ListItem newListItem = new ListItem();
newListItem.Value = drStatus.GetValue(0).ToString();
newListItem.Text = drStatus.GetValue(1).ToString();
cboStatusTypes.Items.Add(newListItem);
if (drStatus["StatusTypeID"].ToString() == stat.StatusTypeID.ToString())
{
cboStatusTypes.SelectedValue = drStatus["StatusTypeID"].ToString();
}
}
drStatus.Close();
}
-----------------------------------------------------------
I cannot close the drStat in GetAllStatusTypes because then I will not be able to return it.
When I create the SqlDataReader drStatus to except the passed SqlDataReader object I close that one. Will this also close the one being passed?
Any help would be very appreciated.
Thank you,
WebGuytoo