我在下面的方法中得到了代码分析错误。
public static OracleCommand CreateStoredProcedureCommand(string name,
OracleConnection connection)
{
return new OracleCommand(name, connection) { CommandType = CommandType.StoredProcedure };
}'StoredProcedureHelper.CreateStoredProcedureCommand(string,
CA2000 : Microsoft.Reliability :在方法Microsoft.Reliability OracleConnection)‘中,对象’命令‘不是沿所有异常路径释放的。在所有对对象的引用超出作用域之前,在对象‘命令’上调用System.IDisposable.Dispose
如何才能解决这一问题而不加以压制呢?
发布于 2012-02-09 09:07:34
当分配给属性时引发异常时,将不会释放该对象。试试这个:
public static OracleCommand CreateStoredProcedureCommand(string name,
OracleConnection connection)
{
OracleCommand result = new OracleCommand(name, connection);
try
{
result.CommandType = CommandType.StoredProcedure;
return result;
}
catch
{
result.Dispose();
throw;
}
}发布于 2012-02-09 08:58:53
它不能,从方法上看,处理对象的责任必须始终由调用方承担。
你必须压制它。
https://stackoverflow.com/questions/9207801
复制相似问题