gpt4 book ai didi

c# - 使用 C# 在 Oracle 中输入 Alter User 语句

转载 作者:太空宇宙 更新时间:2023-11-03 14:58:28 24 4
gpt4 key购买 nike

我正在制作一个工具来在 c# 中重置/解锁 oracle 用户,我通过 sqlplus 使用以下语句来解锁用户“ALTER USER myUserName ACCOUNT UNLOCK;”但是,每次我通过下面的 C# 代码执行该语句时,都会收到此错误!经过数小时的反复试验,我正在寻求帮助!任何帮助都会很棒!

另外,请问有哪位大侠指点一下,提交语句后如何得到Oracle的响应?

提前谢谢大家!

           public ActionResult SubmitRequest()
{
String connectionString ="Data Source = (DESCRIPTION= (ADDRESS=(PROTOCOL=TCP)(HOST=myHost)(PORT=1234)) (CONNECT_DATA=(SID=mySID)));"+
"User Id="+Username+";"+
"password="+password+ ";";

OracleConnection con = new OracleConnection();
con.ConnectionString = connectionString;
if (con.State == ConnectionState.Closed)
{
con.Open();
OracleCommand cmd = new OracleCommand();
cmd.CommandText = "ALTER USER myUserName ACCOUNT UNLOCK;"
cmd.ExecuteNonQuery();
}

con.Close();
return View();
}

错误:

           Server Error in '/' Application.
Invalid operation. The connection is closed.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Invalid operation. The connection is closed.
Source Error:
Line 134: cmd.CommandText = CommandUnlock;
Line 135: con.Open();
Line 136: cmd.ExecuteNonQuery();

而且我在使用“cmd.ExecuteScalar();”时也遇到了同样的错误

最佳答案

点击此链接:

How to run 'alter user' command from C#

否则,您可以像下面这样编写一个过程并从 C# 中执行它。

CREATE OR REPLACE PROCEDURE UNLOCK_USER(P_USER IN VARCHAR2) IS
BEGIN
EXECUTE IMMEDIATE 'ALTER USER ' || P_USER || ' ACCOUNT UNLOCK';
END UNLOCK_USER;

关于c# - 使用 C# 在 Oracle 中输入 Alter User 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47615039/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com