• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

使用C#输入更改用户声明到Oracle中使用C#

c/c++ 来源:leon03 6次浏览

我正在制作一个工具来重置/解锁oracle用户,我通过sqlplus使用以下语句解锁用户“ALTER USER myUserName ACCOUNT UNLOCK;”但是,每次我通过我的C#代码执行语句时,我都会看到这个错误!经过数小时的试验和错误,我正在寻求帮助!任何帮助将是伟大的!使用C#输入更改用户声明到Oracle中使用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; 

版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)