Wednesday, March 7, 2012

closing SQL Connection

hello to all
i am finding my self in confusing problem.

everyay log file of my application increase by 10 GB.
every time i found more than 100 connections open in SDQL Server 2005 under my database.

i an using SQLHELPER Class by microsoft.i ma not putting my code in try-catch block. example

of one of my frequently used function is as follows:

protected Int64 GetMemberID()
{
String SqlSelect = "SELECT * FROM MemberMaster WHERE MemberUserName= '" +

Session["UserName"].ToString() + "'";
SqlDataReader dr1 =

SqlHelper.ExecuteReader(ConfigurationManager.ConnectionStrings["CowcallConnectionString2"].T

oString(), CommandType.Text, SqlSelect);
while (dr1.Read())
{
CurrentMemberID = Int64.Parse(dr1["MemberID"].ToString().Trim());
}
return CurrentMemberID;
}

well i doubt i am opening connection and do not closing it. moreover i do not know how to close connection in above code when i am using sql helper class.
please give me yours suggestion regarding my code even if it is not solving above two problems.

Hi munishbhatia,

use theCommandBehavior to close the connection after use like: SqlHelper.ExecuteReader(CommandBehavior.CloseConnection);

No comments:

Post a Comment