为什么在使用 C# 调用过程时会出现 Oracle 错误? [英] Why do I get an Oracle error when calling a procedure with C#?

查看:36
本文介绍了为什么在使用 C# 调用过程时会出现 Oracle 错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Oracle 11g 中编写了此过程:

I wrote this procedure in Oracle 11g:

create or replace
PROCEDURE P1 
(
   ID_1 IN NUMBER   
  , P_NAME OUT VARCHAR2  
) AS 

  BEGIN
SELECT NAME_ into  p_name  FROM  A1 WHERE ID=ID_1; 
END P1;

我用C#写了这段代码来调用这个过程:

and I wrote this code in C# to call the procedure:

OracleConnection conn = new OracleConnection("User Id=webservice_access;Password=DAMAVAND;Server=ORA11;");
//OracleConnection conn = new OracleConnection("User Id=SYSTEM;Password=123456;Server=ORA11;");
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "P1";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("ID_1", 1);
cmd.Parameters.Add("p_name", OracleType.VarChar, 16).Direction = ParameterDirection.Output;
cmd.Connection.Open();
cmd.ExecuteNonQuery();
Console.WriteLine(cmd.Parameters["p_name"].Value.ToString());
cmd.Connection.Close(); 

但是当我运行 C# 应用程序时,我收到此错误:

but when I run the C# application I get this error:

ORA-06512:在WEBSERVICE_ACCESS.P1",第 10 行
ORA-06512:在第 1 行

ORA-06512:at "WEBSERVICE_ACCESS.P1",Line 10
ORA-06512:at line 1

发生了什么?为什么我会收到这个错误?

What happened? Why do I get that error?

推荐答案

ORA-06512 表示您的过程中有未处理的异常.您的代码中没有错误处理,所以这是合理的.

ORA-06512 indicates an unhandled exception in your procedure. You have no error handling in your code, so that's reasonable.

当然,因为您没有错误处理,所以任何人都很难知道错误是什么.最有可能的是数据:要么您在 A1 where ID=1 中没有记录(即 NO_DATA_FOUND 异常),要么您有多个这样的记录(即 TOO_MANY_ROWS 异常).

Of course, because you have no error handling it's pretty hard for anybody to know what the error is. Most likely is data: either you have no record in A1 where ID=1 (i.e. NO_DATA_FOUND exception) or you have more than one such record (i.e. TOO_MANY_ROWS exception).

ODP 有一个处理异常的类.了解详情.

ODP has a class for handling exceptions. Find out more.

这篇关于为什么在使用 C# 调用过程时会出现 Oracle 错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆