我正在处理遗留系统,最终用户在加载页面时报告异常。这是在ASP.NET 2.0和Oracle.DataAccess中开发的。该异常在任何暂存或开发服务器中都不可重现,并且不一致(即某些时候有效,有些则无效)。
例外情况如下:
System.OutOfMemoryException:内存不足,无法继续执行程序。位于Oracle.DataAccess的Oracle.DataAccess.Client.OracleParameter.PreBind(OracleConnection conn,IntPtr errCtx,Int32 arraySize)的Oracle.DataAccess.Client.OracleParameter.PreBind_Char()处的System.Runtime.InteropServices.Marshal.AllocCoTaskMem(Int32 cb)处.Client.OracleCommand.ExecuteNonQuery()
它在数据访问层中调用的方式如下,删除一些参数只是为了让流程清晰,
public void GetXXXData(UserCredentials credentials,
decimal? P_IN_ID,
string P_IN_TYPE,
out string[] P_OUT_XX_ID,
out string[] P_OUT_XX_NAME,
int? outputArrayLength)
{
if (outputArrayLength == null)
{
outputArrayLength = 3000;
}
OdacCmd cmd = null;
P_OUT_XX_ID = null;
P_OUT_XX_NAME = null;
cmd = OdacFactory.CreateCommand("PK_XX_QAS1.pr_xx_data_q", credentials);
cmd.AddParam("P_IN_ID", P_IN_ID);
cmd.AddParam("P_IN_QUAL_TYPE", P_IN_TYPE);
IDataParameter param_P_OUT_XX_ID = cmd.AddOutputParameterString("P_OUT_XX_ID",
outputArrayLength.Value);
IDataParameter param_P_OUT_XX_NAME = cmd.AddOutputParameterString("P_OUT_XX_NAME",
outputArrayLength.Value);
cmd.ExecuteNonQuery();
P_OUT_XX_ID = OdacFactory.GetStringArray(param_P_OUT_XX_ID.Value);
P_OUT_XX_NAME = OdacFactory.GetStringArray(param_P_OUT_XX_NAME.Value);
}
非常感谢任何帮助。
更新::
在OdacCmd中,连接处理如下
public void Dispose()
{
if (_reader != null)
{
_reader.Close();
_reader.Dispose();
_reader = null;
}
if (_ownsConnection)
{
OracleConnection connection = _cmd.Connection;
if (connection != null)
{
connection.Close();
_cmd.Connection = null;
connection.Dispose();
}
}
_cmd.Dispose();
GC.SuppressFinalize(this);
}
并在ExecuteNonQuery连接中关闭如下,
public int ExecuteNonQuery()
{
if (_ownsConnection)
{
_cmd.Connection.Open();
}
try
{
return _cmd.ExecuteNonQuery();
}
finally
{
if (_ownsConnection)
{
_cmd.Connection.Close();
}
}
}