OracleDataAdapater.Fill() - Random NullReferenceException异常

时间:2015-10-20 17:35:54

标签: odp.net

我遇到了带有随机NULL引用异常的OracleDataAdapater.Fill()方法的问题(请参阅下面的代码和异常堆栈跟踪)。在生产环境中,这种情况在一个月内会发生几次,并且在开发过程中不会出现一致的可重现错误。

我在Visual Studio 2008 C#项目中使用Oracle.DataAccess.DLL(版本2.111.7.20 /运行时版本:v2.0.50727),此代码托管在IIS 7.0中。

这是我使用的ODP.NET版本中的一个已知问题,或者下面的编码有什么问题?

请告诉我。谢谢!

代码:

OracleCommand objSelectCmd = new OracleCommand();

string sql = @"select * from TABLE_1 where MSG_ID = :msgId";

OracleParameter msgIdParam = new OracleParameter();
msgIdParam.OracleDbType = OracleDbType.Varchar2;
msgIdParam.Direction = ParameterDirection.Input;
msgIdParam.Value = "ABC";
msgIdParam.ParameterName = ":msgId";
objSelectCmd.Parameters.Add(msgIdParam);

objSelectCmd.Connection = connection;
objSelectCmd.CommandText = sql;
objSelectCmd.CommandType = CommandType.Text;
OracleDataAdapter objAdaptor = new OracleDataAdapter(objSelectCmd);
DataTable myDataTable = new DataTable();
objAdaptor.Fill(myDataTable);

我随机获得异常OracleDataAdaper.Fill()方法。

System.NullReferenceException: Object reference not set to an instance of an object.
   at Oracle.DataAccess.Client.OracleDataReader..ctor(OracleConnection connection, IntPtr[] opsSqlCtx, IntPtr opsDacCtx, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, OpoDacValCtx* pOpoDacValCtx, MetaData metaData, Int32 resultCount, CommandBehavior commandBehavior, Hashtable safeMapping, String commandText, Int32 freeOpsSqlCtx)
   at Oracle.DataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior)
   at Oracle.DataAccess.Client.OracleDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)

0 个答案:

没有答案