ADO.Net Command and passing Pars to Oracle SP's
I have problems:
1:
to find the correct parameter type mapping between the ADO.Net OleDbParameter.OleDbDataType and the datatype of the Oracle Stored procedure
2:
to call a stored procedure that has a Ref Cursor (or more then just one) as OUT parameter and any IN parameter. Calling SP's that have only one Ref Cursor as the one and only OUT parameter work fine.
We are able to call any SP's to Insert/Update/Delete data but we are not able to implement the call to a SP that returns the result of a Query with a Where clause that is build passing a
parameter to the SP.
Some more detailed error information an Scenario:
Calling an Oracle SP that only return a Ref Cursor works fine:
Sample: Oracle Code of the SP (run that with sqplplus):
__________________________________________
CREATE OR REPLACE PACKAGE pkgOrders AS
TYPE orderscur IS REF CURSOR;
PROCEDURE GetOrders( p_cursor OUT orderscur );
END pkgOrders;
/
CREATE OR REPLACE PACKAGE BODY pkgOrders AS
PROCEDURE GetOrders( p_cursor OUT orderscur ) IS
BEGIN
OPEN p_cursor FOR
SELECT OrderId, CustomerId, Status, OrderDate, Total
FROM Orders
ORDER BY OrderId;
END GetOrders;
END pkgOrders;
/
Show Errors
__________________________________________
.Net Source Code to build command and get the OLEDB rowset
__________________________________________
OleDbConnection mCn = new OleDbConnection(
"Provider=MSDAORA.1;Password=rg;User ID=rg;Data Source=rg;Persist Security Info=True");
mSelCmd = new OleDbCommand("RG.PKGORDERS.GETORDERS");
mSelCmd.CommandType=CommandType.StoredProcedure;
DataTable dt = new DataTable("Orders");
OleDbDataAdapter da = new OleDbDataAdapter();
da.MissingSchemaAction=MissingSchemaAction.AddWithKey;
mSelCmd.Connection=mCn;
da.SelectCommand=mSelCmd;
mCn.Open();
da.Fill(dt);
__________________________________________
Calling an Oracle SP that should return a Ref Cursor
(just one single row as result of a parametrized
SP-call) does not work.
Sample: Oracle Code of the SP (run that with sqplplus):
__________________________________________
CREATE OR REPLACE PACKAGE pkgOrders AS
TYPE orderscur IS REF CURSOR;
PROCEDURE GetOrder( p_cursor OUT orderscur ,
p_OrderID IN RG.Orders.OrderID%TYPE );
END pkgOrders;
/
CREATE OR REPLACE PACKAGE BODY pkgOrders AS
PROCEDURE GetOrder( p_cursor OUT orderscur ,
p_OrderID IN RG.Orders.OrderID%TYPE ) IS
BEGIN
OPEN p_cursor FOR
SELECT OrderId, CustomerId, Status, OrderDate, Total
FROM Orders
WHERE OrderId = p_OrderID;
END GetOrder;
END pkgOrders;
/
Show Errors
__________________________________________
.Net Source Code to build command and get rowset
__________________________________________
OleDbConnection mCn = new OleDbConnection(
"Provider=MSDAORA.1;Password=rg;User ID=rg;Data Source=rg;Persist Security Info=True");
mSelCmd = new OleDbCommand("RG.PKGORDERS.GETORDERS");
mSelCmd.CommandType=CommandType.StoredProcedure;
mSelCmd.Parameters.Add(new System.Data.OleDb.OleDbParameter("P_ORDERID",
System.Data.OleDb.OleDbType.Decimal ,
46, System.Data.ParameterDirection.Input, true,
((System.Byte)(15)), ((System.Byte)(46)), "", System.Data.DataRowVersion.Current, null));
mSelCmd.Parameters["P_ORDERID"].Value=6;
DataTable dt = new DataTable("Orders");
OleDbDataAdapter da = new OleDbDataAdapter();
da.MissingSchemaAction=MissingSchemaAction.AddWithKey;
mSelCmd.Connection=mCn;
da.SelectCommand=mSelCmd;
mCn.Open();
da.Fill(dt);
__________________________________________
When calling the SP in that way the Oracle Error comes up:
"Wrong number or type of parameters".
WHAT I TRIED TO BE SUCCESSFULL:
- changed the OLEDB provider from Microsoft (MSDAORA.1)
to Oracle (OraOLEDB.Oracle.1)
- tried to declare the p_cursor as an parameter (Error:
"Unknown Error in OLEDB-Porvider") of different
OleDbDataTypes (IUknown, Variant, ...)
- tried to implement tha SP as an Oracle Function instead
of an Procedure (Error: "<Name> is not an procedure or
does not exists")
- tried to get an OldDbDataReader instead of using a
data adapter. That crashed with the same errors as above
when calling the ExecuteRead method of the OleDbCommand
to get the reader itself (before handling custom parameter
mapping).
WHAT WORKS:
- Calling an Oracle SP that takes one ore more parameters
of different (Oracle) data types marked as well as IN
as as OUT parameters (see complete code). So Insert/Update
Delete Statement have been successful.
!!! PLEASE HELP !!!