views:

170

answers:

1

I'm trying to map OleDb parameters to an Oracle Function. I was able to do this using the System.Data.Oracle namespace but then found that this is depricated, so I thought i would re-write it as OldDb to avoid installing the Oracle Provider.

I have defined the following oracle function as an example:

create function GetImagePath (AIRSNumber in number)
   return varchar2
is
   begin
     return '\\aiimg524\images\Ofndrtrk\2010\01\0kvrv1p000lcs74j';
   end;

and I'm calling it using the following code:

using (var command = new OleDbCommand())
        {
          command.Connection = con;
          command.CommandText = ConfigurationManager.AppSettings[OTRAK_PHOTO_FUNC];
          command.CommandType = CommandType.StoredProcedure;

          string parm = ConfigurationManager.AppSettings[OTRAK_PHOTO_PARM];

          command.Parameters.Add(parm, OleDbType.Decimal); // maps to oracle Number
          command.Parameters[parm].Direction = ParameterDirection.Input;
          command.Parameters[parm].Value = airsNumber;

          command.Parameters.Add(RETURN_VALUE, OleDbType.Variant); // maps to Oracle varchar2
          command.Parameters[RETURN_VALUE].Direction = ParameterDirection.ReturnValue;
          try
          {
            con.Open();
            command.ExecuteNonQuery();
            path = command.Parameters[RETURN_VALUE].Value.ToString();
          }

I tried a bunch of different OleDB types for the parameter and the return value. the current attempt is from a mapping table i found on the web that said number = decimal and varchar2 = variant. I'm about to try every permutation of types in the enum and wanted to ask for help. the not so useful error message i get is:

[System.Data.OleDb.OleDbException] = {"ORA-06550: line 1, column 7:\nPLS-00306: wrong number or types of arguments in call to 'GETIMAGEPATH'\nORA-06550: line 1, column 7:\nPL/SQL: Statement ignored"}

A: 

This actually had nothing to do with the type of the parameters but the order. Using the OleDb provider for Oracle does not respect the names of the parameters in the parameter collection but rather the order that the parameters are added. Wwhen calling an oracle function, the return value is a free parameter that must be declared first. by adding my return value parameter and then the actual function parameter things started working.

using the command.Parameters.AddWithValue(parm, value) also simplifies things a bit.

Mark Davis