【问题标题】:Executing Stored Procedure Oracle C#执行存储过程 Oracle C#
【发布时间】:2014-12-01 16:49:13
【问题描述】:

我正在尝试执行我在我的 oracle DB 上创建的过程,但我遇到了问题,因为它从未找到该过程,我已经按照此处 (http://www.devart.com/dotconnect/oracle/docs/) 上的 oracle 连接文档进行操作,但它没有效果不好。这是我的代码:

public static void ActualizarPacienteNn(Int64 idPacienteNN, Int64 idPaciente, string nombreUsuario, string contrasena)
{
    OracleConnection conexion = new OracleConnection();
    conexion = GenerarConexionOracle(nombreUsuario, contrasena);
    /*  
    OracleParameter[] parametros_procedimiento=new OracleParameter[]
    {
        new OracleParameter("ID_HCL_NN",idPacienteNN),
        new OracleParameter("ID_HCL_PACIENTE",idPaciente)
    };
    */

    OracleCommand comando = new OracleCommand();//se crea un comando
    comando.CommandType = System.Data.CommandType.StoredProcedure;
    comando.CommandText = "PROCEDURE";
    comando.Connection = conexion;
    comando.ParameterCheck = true;

    try
    {
        conexion.Open();
        OracleDataAdapter da = new OracleDataAdapter(comando);
        comando.ExecuteNonQuery();
    }

    catch (OracleException e)
    {
        Console.WriteLine(e);
        conexion.Close();

    }

    conexion.Close();
}

错误提示,OBJECT "PROCEDURE" 不存在。 (而且我确信该程序存在)。

我正在使用 devart dotconnect 和 oracle DB 11g。谢谢。

【问题讨论】:

  • 并且您的存储过程名称是“PROCEDURE”?
  • 存储过程是否属于您在连接字符串中使用的同一架构/用户?如果没有,您需要使用适当的模式来限定过程名称,例如“someschema.PROCEDURE”。这也可能是您在连接字符串中使用的帐户没有被授予存储过程的权限的问题。如果您使用与连接字符串中相同的凭据通过 SQL Plus(或类似)登录,您可以从那里查看并执行存储过程吗?
  • 这是您缺少的行:comando.CommandText = "nameOfTheStoredProcedure";....
  • @Robert Rozas,OP 在代码中有 CommandText
  • 是的,但是字符串是错误的……除非他的 SP 被称为“Procedure”

标签: c# oracle stored-procedures oracle11g


【解决方案1】:

根据文档,您应该尝试这样的事情

public static void ActualizarPacienteNn(Int64 idPacienteNN, Int64 idPaciente, string nombreUsuario, string contrasena)
{
  //Establish connection
  OracleConnection conexion = new OracleConnection();
  conexion = GenerarConexionOracle(nombreUsuario, contrasena);

  conexion.Open();
  //Set up comando to reference stored procedure 'usp_ActualizaPaciente'
  OracleCommand comando = new OracleCommand("usp_ActualizaPaciente", myConn);
  comando.CommandType = System.Data.CommandType.StoredProcedure;
  comando.ParameterCheck = true;

  //Sample of how to bind parameters to the Stored Procedure
  OracleParameter myInParam1 = new OracleParameter();
  myInParam1.Value = idPaciente;
  myInParam1.ParameterName = "idPaciente";
  comando.Parameters.Add(myInParam1);
  myInParam1.Direction = System.Data.ParameterDirection.Input;

  //Execute the procedure.
  comando.ExecuteNonQuery();
  Console.WriteLine("Done");
  conexion.Close();
}

文档:http://www.devart.com/dotconnect/oracle/articles/parameters.html

【讨论】:

    猜你喜欢
    • 2011-06-19
    • 1970-01-01
    • 1970-01-01
    • 2011-11-07
    • 2010-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多