我正在尝试使用托管ODP.Net和Enterprise Library一个一个地执行多个 (3) 存储过程。每个存储过程都返回一个OUT 游标,每个游标都被命名为“ cur_out ”。奇怪的是,第一个存储过程总是返回记录,但是随后调用 ExecuteDataSet() 以获取剩余的两个 SP 从不返回任何记录。这与 System.Data.OracleClient 完美配合,所以我知道存储过程本身没有问题。我无法弄清楚为什么这些 SP 没有返回任何东西。下面是我的示例代码:
DbCommand cmd = DB.GetStoredProcCommand("EBS_EOM_PKG.SP1");
DB.AddInParameter(cmd, "PI_PARAM1", DbType.AnsiString);
DB.SetParameterValue(cmd, "PI_PARAM1", param1);
DB.AddInParameter(cmd, "PI_PARAM2", DbType.AnsiString);
DB.SetParameterValue(cmd, "PI_PARAM2", param2);
if (cmd is Oracle.ManagedDataAccess.Client.OracleCommand)
{
OracleParameter cur = new OracleParameter("cur_out",
OracleDbType.RefCursor, 0,
ParameterDirection.Output, true,
0, 0, String.Empty,
DataRowVersion.Current,
Convert.DBNull);
cmd.Parameters.Add(cur);
}
DataSet dsSub = DB.ExecuteDataSet(cmd); <--WORKS i.e. returns records
cmd = DB.GetStoredProcCommand("EBS_EOM_PKG.SP2");
DB.AddInParameter(cmd, "PI_PARAM1", DbType.AnsiString);
DB.SetParameterValue(cmd, "PI_PARAM1", param1);
DB.AddInParameter(cmd, "PI_PARAM2", DbType.AnsiString);
DB.SetParameterValue(cmd, "PI_PARAM2", param2);
if (cmd is Oracle.ManagedDataAccess.Client.OracleCommand)
{
OracleParameter cur = new OracleParameter("cur_out",
OracleDbType.RefCursor, 0,
ParameterDirection.Output, true,
0, 0, String.Empty,
DataRowVersion.Current,
Convert.DBNull);
cmd.Parameters.Add(cur);
}
DataSet dsSub1 = DB.ExecuteDataSet(cmd); <--FAILS i.e. no records returned
DataTable dt1 = dsSub1.Tables[0];
dsSub1.Tables.Remove(dt1);
dt1.TableName = "Ported DataTable 1";//Provide name
explicitly to prevent name conflicts with existing datatable
dsSub.Tables.Add(dt1);
cmd = DB.GetStoredProcCommand("EBS_EOM_PKG.SP3");
DB.AddInParameter(cmd, "PI_PARAM1", DbType.AnsiString);
DB.SetParameterValue(cmd, "PI_PARAM1", param1);
DB.AddInParameter(cmd, "PI_PARAM2", DbType.AnsiString);
DB.SetParameterValue(cmd, "PI_PARAM2", param2);
if (cmd is Oracle.ManagedDataAccess.Client.OracleCommand)
{
OracleParameter cur = new OracleParameter("cur_out",
OracleDbType.RefCursor, 0,
ParameterDirection.Output, true,
0, 0, String.Empty,
DataRowVersion.Current,
Convert.DBNull);
cmd.Parameters.Add(cur);
}
DataSet dsSub2 = DB.ExecuteDataSet(cmd); <--FAILS i.e. no records returned
DataTable dt2 = dsSub2.Tables[0];
dsSub2.Tables.Remove(dt2);
dt2.TableName = "Ported DataTable 2";//Provide name
explicitly to prevent name conflicts with existing datatable
dsSub.Tables.Add(dt2);
有人可以指出我在这里缺少什么吗?有什么我可以做不同的事情吗?请注意,我使用的 Oracle 12c DB 在单个存储过程中返回多个引用游标时存在问题,因此必须单独执行这些,然后将结果组合到单个数据集中。