How to run an oracle database via c# with no data return?

Asked

Viewed 107 times

0

I am developing a WEBAPI in c# that runs a precedent on Oracle and after this procedure, it queries a table. This precedent only deletes data from a time table and inserts the the data informed in it and then displays them with some more information. When I run directly on Oracle, it works: (run Minha_procedure(KEY, YEAR, MONTH)). BS: She has a cursor. But in my code is not running, It follows below my method:

public void ExecutarProcedure(string chave, string mes, string ano)
    {
        OpenConnection();

        OracleCommand cmd = new OracleCommand("BDRH_APPS.SP_CARGA_SITE", Con);
        cmd.CommandType = System.Data.CommandType.StoredProcedure;

        OracleDataAdapter da = new OracleDataAdapter();

        cmd.Parameters.Add("CHAVE_PAR", chave);
        cmd.Parameters.Add("ANOFOLHA_PAR",ano );
        cmd.Parameters.Add("MESFOLHA_PAR",mes );

        // execute the command to open the ref cursors
        cmd.ExecuteNonQuery();           


        cmd.Dispose();

        CloseConnection();

    }

Thank you!

  • And what’s the mistake?

  • no error, simply not giving the run in the database

  • Oraclecommand has been deprecated. http://go.microsoft.com/fwlink/? Linkid=144260

  • But the problem seems to be in connection management, which makes the method OpenConnection(); and where the attribute comes from Con?

  • If not from the bug but also not "run", it may be that commit is missing. Hard to say...

  • Leandro, this class inherits from another connection class with the protected database Oracleconnection Con; //Connection to the database.. protected Oraclecommand Cmd; //Execute SQL commands.. protected Oracledatareader Dr; //Read query data.. protected Oracletransaction Tr; //transactions (commit/rollback)

  • without seeing these others there is no help, but still think you are not running the command on the open connection... submit a [MCVE]

Show 2 more comments

1 answer

0

I could solve it! I created an output cursor in oracle (prc out sys_refcursor) and managed to bring the data.

Thank you all!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.