I'm using a web service, that is invoked every few ms, to expose some functionalities. Basically these functionalities are based on store procedures, and all my methods look like the follow:
[WebMethod]
public bool CheckMessageForMES( out int returnCode, out int messagePK, out String messageBody, out bool isRowFetched )
{
using ( SqlConnection connection = new SqlConnection() )
{
using(SqlCommand command = _dl.GetSqlCommandForStoredProcedure(DataLayer.SP_NAME, connection)){
SqlParameter parameterReturnCode = _dl.CreateParameter("@returnCode", DbType.Int16, ParameterDirection.Output);
SqlParameter parameterMessagePK = _dl.CreateParameter("@messagePK", DbType.Int32, ParameterDirection.Output);
SqlParameter parameterMessageBody = _dl.CreateParameter("@messageBody", DbType.Xml, ParameterDirection.Output);
SqlParameter parameterIsRowFetched = _dl.CreateParameter("@isRowFetched", DbType.Int16, ParameterDirection.Output);
SqlParameter[] parameters = {
parameterReturnCode,
parameterMessagePK,
parameterMessageBody,
parameterIsRowFetched
};
command.Parameters.AddRange(parameters);
connection.Open();
using (SqlDataReader r = command.ExecuteReader() )
{
r.Close();
}
connection.Close();
returnCode = int.Parse(parameterReturnCode.Value.ToString());
messagePK = int.Parse(parameterMessagePK.Value.ToString());
messageBody = parameterMessageBody.Value.ToString();
isRowFetched = int.Parse(parameterIsRowFetched.Value.ToString()) > 0;
}
}
return isRowFetched;
}
Webserver process takes memory and never releases, and using VS10 tools the problem seems located in command.ExecuteReader(). Do you know why?
I'm implementing in the right way this method?
Thanks!