C# Oracle 使用输出参数执行存储过程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6491159/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C# Oracle execute stored procedure with output parameter
提问by Rik De Peuter
Situation:
I'm trying to run a stored procedure that has an output parameter, which I need to catch.
I use C# 3.5 and the OracleClient with an OleDbConnection.
情况:
我正在尝试运行一个具有输出参数的存储过程,我需要捕获该参数。
我使用 C# 3.5 和带有 OleDbConnection 的 OracleClient。
Research:
I've been looking around for other ways, but as far as I can tell I'm doing it correct. Microsoft supportand various other forums.
研究:
我一直在寻找其他方法,但据我所知,我做得对。Microsoft 支持和各种其他论坛。
Problem:
When I do the cmd.ExecuteNonQuery() it just gets stuck. No error or anything, it just stops there and holds the Thread.
When I try via OleDbDataReader or the Scalar it's nothing better.
If I change the CommandText (remove package name) it gives error that it can't find the stored procedure, so I know that is correct at least.
问题:
当我执行 cmd.ExecuteNonQuery() 时,它会卡住。没有错误或任何东西,它只是停在那里并保持线程。
当我通过 OleDbDataReader 或 Scalar 尝试时,没有什么比这更好的了。
如果我更改 CommandText(删除包名称),它会给出找不到存储过程的错误,所以我至少知道这是正确的。
Code:
Oracle:
代码:
甲骨文:
PROCEDURE deleteThemakaart
(an_seqthemakaart IN NUMBER, an_retval OUT NUMBER)
....
C#:
C#:
double InputValue = 777;
try
{
OleDbConnection con = new OleDbConnection(...);
con.Open();
OleDbCommand cmd = new OleDbCommand()
{
CommandText = "thema.pckg_themakaarten.deleteThemakaart",
Connection = con,
CommandType = CommandType.StoredProcedure,
};
OleDbParameter input = cmd.Parameters.Add("an_seqthemakaart", OleDbType.Double);
OleDbParameter output = cmd.Parameters.Add("an_retval", OleDbType.Double);
input.Direction = ParameterDirection.Input;
output.Direction = ParameterDirection.Output;
input.Value = InputValue;
cmd.ExecuteNonQuery();
return (double)output.Value;
}
catch (Exception ex)
{
...
}
finally
{
con.Close();
}
Any help is very welcome :)
非常欢迎任何帮助:)
Edit: some code is below in comment, but hasn't gotten me any further so far :(
编辑:一些代码在评论下方,但到目前为止还没有让我更进一步:(
Greetings
你好
回答by Rik De Peuter
I found the trouble maker... one of the tables that the procedure used was locked.
我找到了麻烦制造者......该程序使用的表之一被锁定。