我正在使用每隔几毫秒调用一次的 Web 服务来公开一些功能。基本上这些功能是基于存储过程的,我所有的方法如下所示:
[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 进程占用内存并且从不释放,并且使用 VS10 工具问题似乎位于 command.ExecuteReader() 中。你知道为什么吗?
我正在以正确的方式实施这种方法?
谢谢!