C# Oracle 执行带有输出参数的存储过程
情况:
我正在尝试运行一个具有输出参数的存储过程,我需要捕获该参数。
我使用 C# 3.5 和带有 OleDbConnection 的 OracleClient。
研究:
我一直在寻找其他方法,但据我所知,我做得正确。 Microsoft 支持和各种其他论坛。
问题:
当我执行 cmd.ExecuteNonQuery() 时,它就会卡住。没有错误或任何东西,它只是停在那里并保留线程。
当我尝试通过 OleDbDataReader 或 Scalar 时,没有什么比这更好的了。
如果我更改 CommandText(删除包名称),它会给出找不到存储过程的错误,所以我知道这至少是正确的。
代码:
Oracle:
PROCEDURE deleteThemakaart
(an_seqthemakaart IN NUMBER, an_retval OUT NUMBER)
....
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();
}
非常欢迎任何帮助:)
编辑:一些代码在下面的评论中,但到目前为止还没有让我进一步:(
问候
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.
Research:
I've been looking around for other ways, but as far as I can tell I'm doing it correct. Microsoft support and various other forums.
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.
Code:
Oracle:
PROCEDURE deleteThemakaart
(an_seqthemakaart IN NUMBER, an_retval OUT NUMBER)
....
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了麻烦制造者...该过程使用的表之一被锁定。
I found the trouble maker... one of the tables that the procedure used was locked.