0

I would like to call a (Oracle) Procedure from C#. My Code:

try
{
    OracleConnection myOracleConnection = new OracleConnection(connectionString);
    myOracleConnection.Open();
    OracleCommand command = myOracleConnection.CreateCommand();
    command.CommandText = String.Format("BEGIN MISSINGTABLES ('{0}', '{1}'); END;", "PEKA_ERP_001", "ASE_ERP_001");
    command.CommandType = System.Data.CommandType.Text;
    command.ExecuteNonQuery();
    myOracleConnection.Close();
}
catch (OracleException e)
{
    throw e;
}
catch (Exception e)
{
    throw e;
}

The Procedure:

CREATE OR REPLACE PROCEDURE MISSINGTABLES (S1 IN VARCHAR2, S2 IN VARCHAR2) AS
BEGIN [...] 

on command.ExecuteNonQuery(); I get an Exception..:

PL/SQL: Statement ignored
OracleException Unhandled

What I'm doing wrong?

4
  • 1
    Why are you concatenating a string an not using parameters? Commented Jan 16, 2012 at 14:20
  • Because I don't really know, how I use the Parameters. You can see, that I need them between the -> BEGIN ... END Statement. How to do then the Placeholders ..? Commented Jan 16, 2012 at 14:29
  • There are many tutorials on the web, did you even search before asking? Commented Jan 16, 2012 at 14:40
  • sry guys, next time, I will search ;) Did it Commented Jan 16, 2012 at 14:48

1 Answer 1

1

Did it :)

OracleCommand command = myOracleConnection.CreateCommand();
command.CommandText = "MISSINGTABLES";
command.Parameters.Add(new OracleParameter("S1", OracleType.VarChar)).Value = "PEKA_ERP_001";
command.Parameters.Add(new OracleParameter("S2", OracleType.VarChar)).Value = "ASE_ERP_001";
command.CommandType = System.Data.CommandType.StoredProcedure;
command.ExecuteNonQuery();
myOracleConnection.Close();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.