oracle 在 C# 中执行参数化查询时出现 ORA-01745 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16104218/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:35:37  来源:igfitidea点击:

ORA-01745 error while executing parameterized queries in c#

c#.netoracle

提问by Bahamut

I'm doing something like

我正在做类似的事情

...
OracleCommand oCommand = new OracleCommand();
oConnection.Open();
oCommand.Connection = oConnection;
oCommand.CommandText = "SELECT * FROM employees WHERE user = :User";
oCommand.Parameters.AddWithValue(":Name", "Employee1");

DbDataReader dbRdr = oCommand.ExecuteReader();

then this throws an exception:

那么这会引发异常:

ORA-01745: invalid host/bind variable name

ORA-01745: 无效的主机/绑定变量名

EDIT: connection string looks like this:

编辑:连接字符串如下所示:

"Data Source=orcl;Persist Security Info=True;User ID=user_id;Password=pwd;Unicode=True"

No error after the oConnection.Open();so I assume my connection string is correct.

之后没有错误,oConnection.Open();所以我假设我的连接字符串是正确的。

On which part did I make a mistake?

我在哪个部分犯了错误?

回答by CloudyMarble

ORA-01745: invalid host/bind variable name

Cause: A colon in a bind variable or INTO specification was followed by an inappropriate name, perhaps a reserved word.

Action: Change the variable name and retry the operation.

ORA-01745: 无效的主机/绑定变量名

原因:绑定变量或 INTO 规范中的冒号后跟不适当的名称,可能是保留字。

行动:更改变量名称并重试操作。

from here

这里

To check what are reserved words, click here

要检查什么是保留字,请单击此处

回答by aquaraga

Wrap around an oracle connection usingblock and supply the correct connectionString.

环绕一个 oracle 连接using块并提供正确的 connectionString。

using (OracleConnection con = new OracleConnection(connectionString)) {
    OracleCommand oCommand = new OracleCommand(queryString, connection);
    ....
}