M
mc
I have a ASP.NET app which I have recently converted from OleDB to
SqlClient, however when I Get a connection, use and close it, It stays
open (Process Info in Sql Server Enterprise Manager say the connection
is sleeping) and very soon I hit the currently defined 100 connections
limit?
Why is this the code I use is as follows:-
using (SqlCommand innerConnect = DBHelper.GetConnection())
{
using (SqlCommand innerCmd = new SqlCommand("StoredProcName",
innerConnect))
{
innerCmd.CommandType = CommandTyle.StoredProcedure;
innerCmd.Para,eter.AddWithValue("@Parm1", Variable1);
SqlDataReader innnerRS = innerCmd.ExecuteReader();
if (innerRS.Read())
{
lblNumber1.Text = innerRS.GetString(innerRS.GetOrdinal("RetCol1"));
}
innerRS.Close();
}
}
The DBHelper class contains a static method as follows: -
public static SqlConnection GetConnection()
{
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr1"].ConnectionString);
conn.Open();
return conn;
}
SqlClient, however when I Get a connection, use and close it, It stays
open (Process Info in Sql Server Enterprise Manager say the connection
is sleeping) and very soon I hit the currently defined 100 connections
limit?
Why is this the code I use is as follows:-
using (SqlCommand innerConnect = DBHelper.GetConnection())
{
using (SqlCommand innerCmd = new SqlCommand("StoredProcName",
innerConnect))
{
innerCmd.CommandType = CommandTyle.StoredProcedure;
innerCmd.Para,eter.AddWithValue("@Parm1", Variable1);
SqlDataReader innnerRS = innerCmd.ExecuteReader();
if (innerRS.Read())
{
lblNumber1.Text = innerRS.GetString(innerRS.GetOrdinal("RetCol1"));
}
innerRS.Close();
}
}
The DBHelper class contains a static method as follows: -
public static SqlConnection GetConnection()
{
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr1"].ConnectionString);
conn.Open();
return conn;
}