我们使用一个涉及多个全局临时表和PL SQL数组的存储过程,以避免使用动态SQL查询,并且由于我们可能会返回大量记录。然而,当我们试图从结果中读取时,我们遇到了一个小问题。
我们过去的模式是使用如下代码从结果中读取:
DataTable result = new DataTable();
const string procName = "some proc";
using (var connection = new OracleConnection("some connection string"))
using (var command = new OracleCommand(procName, connection))
{
command.CommandType = CommandType.StoredProcedure;
command.BindByName = true;
command.Parameters.Add(new OracleParameter("my_ref_cursor", OracleDbType.RefCursor)
{
Direction = ParameterDirection.Output
});
connection.Open();
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
// some logic here
}
}
connection.Close();
}然而,当我们试图从阅读器读回结果时,它跳过解析循环,就好像没有数据一样。当我们在TOAD中复制调用时,我们可以毫无问题地返回结果。
我们已经猜到,当我们试图读回结果时,驱动程序正在执行提交,但我们不确定如何绕过这一点。我们已经尝试使用以下方法:
connection.BeginTransaction(IsolationLevel.ReadUncommitted);但这抛出了一个可爱的异常,虽然明确,但并不能帮助我实际解决问题。
System.ArgumentException was unhandled by user code
HResult=-2147024809
Message=IsolationLevel must be ReadCommitted or Serializable
Parameter name: isolationLevel
Source=Oracle.ManagedDataAccess
ParamName=isolationLevel
StackTrace:
at Oracle.ManagedDataAccess.Client.OracleConnection.BeginTransaction(IsolationLevel isolationLevel)有没有想过我们能不能做我们想做的事?
发布于 2015-11-03 21:15:27
如错误消息中所述,不允许使用隔离级别IsolationLevel.ReadUncommitted。您必须使用ReadCommitted (默认值)或Serializable。
您是否使用ON COMMIT DELETE ROWS (默认设置)创建了全局临时表?
尝试使用以下命令创建表
CREATE GLOBAL TEMPORARY TABLE ....
(
...
)
ON COMMIT PRESERVE ROWS;https://stackoverflow.com/questions/33499813
复制相似问题