Trying to call a function from C#
998035Mar 20 2013 — edited Mar 20 2013Hi all,
I am having problems calling a function that returns a sys refcursor and takes a varchar2 as an input. From the SQL Developer IDE I see that the function is run like
DECLARE
X_AR_MHTR VARCHAR2(200);
v_Return sys_refcursor;
BEGIN
X_AR_MHTR := 697678;
v_Return := CMS_SMS.FOR_WEB.WEB_STATION_1(
X_AR_MHTR => X_AR_MHTR
);
/* Legacy output:
DBMS_OUTPUT.PUT_LINE('v_Return = ' || v_Return);
*/
:v_Return := v_Return; --<-- Cursor
END;
here is my C# code
public static void getTilemetriseis(bool isLemessos, string AMSet, out OracleDataReader dr)
{
DataSet ds = new DataSet();
OracleDataAdapter ad = new OracleDataAdapter();
OracleCommand cmd = new OracleCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "CMS_SMS.FOR_WEB.WEB_Station_1";
if (isLemessos)
{
cmd.Parameters.Add("X_AR_MHTR", OracleDbType.Varchar2, ConfigurationManager.AppSettings["LemessosArMhtr"].ToString(), ParameterDirection.Input);
cmd.Parameters.Add(new OracleParameter("anexoflCur", OracleDbType.RefCursor, ParameterDirection.ReturnValue));
// ad.SelectCommand.CommandText = string.Format(@"select m_code,ar_mhtr,city,address,stcode
// from cms_sms.FOR_WEB.flowmetersall where ar_mhtr = {0}
// order by length(ar_mhtr),ar_mhtr", ConfigurationManager.AppSettings["LemessosArMhtr"].ToString());
}
else
{
cmd.Parameters.Add("X_AR_MHTR", OracleDbType.Varchar2, "697678", ParameterDirection.Input);
cmd.Parameters.Add(new OracleParameter("v_Return", OracleDbType.RefCursor, ParameterDirection.ReturnValue));
// ad.SelectCommand.CommandText = string.Format(@"select m_code,ar_mhtr,city,address,stcode
// from cms_sms.FOR_WEB.flowmetersall where ar_mhtr= -1
// order by length(ar_mhtr),ar_mhtr", AMSet);
}
cmd.Connection = OracleDBManager.getOracleCMSConnection();
cmd.ExecuteNonQuery();
dr = (OracleDataReader)cmd.Parameters["v_Return"].Value;
cmd.Connection.Close();
}
The error rises on cmd.ExecuteNonQuery() and is described as
ORA-06550:
PLS-00306: wrong number or type of argument
Any ideas?