开发者

Calling Oracle Stored Procedure. Getting 'No Data Found' Exception

开发者 https://www.devze.com 2023-02-10 15:56 出处:网络
I\'m trying to call an Oracle Stored Procedure which returns XMLType data, but all I receive is a \'No Data Found Exception\'. The table has data. I have checked that, and then double checked.

I'm trying to call an Oracle Stored Procedure which returns XMLType data, but all I receive is a 'No Data Found Exception'. The table has data. I have checked that, and then double checked. Is there something wrong in my code that calls the stored procedure. Maybe something obvious, I am completely missing.

using (OracleConnection dbc = new OracleConnection("Data Source=test; User ID=user; Password=pwd"))
{
   dbc.Open();
   using (DbTransaction trans = dbc.BeginTransaction())
   {
      try
      {
         DbCommand comm = dbc.CreateCommand();
         comm.CommandType = CommandType.StoredProcedure;
         comm.CommandText = "TestStoredProcedure";
         comm.Transaction = trans;

         OracleParameter returnParam = new OracleParameter("result", OracleDbType.XmlType);
         returnParam.Direction = ParameterDirection.ReturnValue;
         comm.Parameters.Add(returnParam);

         OracleParameter param1 = new OracleParameter("param1", OracleDbType.Varchar2);
         param1.Direction = ParameterDirection.Input;
         param1.Size = 70;
         param1.Value = "testing";
         comm.Parameters.Add(param1);

         OracleParameter param2 = new OracleParameter("param2", OracleDbType.Varchar2);
         param1.Direction = ParameterDirection.Input;
         param1.Size = 70;
         param1.Value = "testing";
         comm.Parameters.Add(param2);

         OracleParameter param3 = new OracleParameter("param3", OracleDbType.Date);
         param1.Direction = ParameterDirection.Input;
         param1.Value = Convert.ToDateTime("1/18/2011 12:00:00 AM");
         comm.Parameters.Add(param3);

         comm.ExecuteNonQuery(); //exception at this line

         OracleXmlType oracleXml = (OracleXmlType)comm.Parameters["result"].Value;
         XmlDocument xmlDoc = oracleXml.GetXmlDocument();
      }
      catch (Exception ex)
      {
          Console.WriteLine(ex.ToString());
      }
   }
}

The stored procedure:

declare
  -- Non-scalar parameters requir开发者_开发百科e additional processing 
  result sys.xmltype;
begin
  -- Call the function
  result := mktadmin.test_package.test(param1 => :testval1,
                                       param2 => :testval2,
                                       param3 => :testval3);
end;

EDIT: Ignore any discrepancy in names. I had to edit them to post here.


Looks like you are overwriting param1 properties in the param2 and param3 section assignments.


It would be useful to see the stored procedure. You usually get the no data found error when doing a select into that yields no results.

0

精彩评论

暂无评论...
验证码 换一张
取 消