How to store a parameter value in oracle procedure from webservice
So what i am looking to do is use a web service call to implement an oracle procedure. To be more specific: I what it so that when i put a value into a parameter in my web service and run it, i want that to be the value sent to the procedure in oracle and then after successfully running to return to the web service as true.
What i have currently tried to to is this:
public bool InsertMachineModels(string MachineModel)
{
logger.DebugFormat("FilteredReportInputsDAO.InsertMachineModel({0})", MachineModel);
bool retVa开发者_如何学运维l = true;
using (OracleConnection conn = new OracleConnection(connectionString))
{
using (OracleCommand cmd = new OracleCommand("Admin_Utilities.InsertMachineModel", conn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("pMachineModel", OracleType.Cursor).Value = Convert.ToString(MachineModel);
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
if (IsErrorLogging)
logger.Error("FilteredReportInputsDAO.InsertMachineModels() Exception: ", ex);
retVal = false;
}
finally
{
conn.Close();
}
}
}
return retVal;
}
Below you will find my procedure which runs correctly when implemented in sql developer.
procedure InsertMachineModel( pMachineModel in nvarchar2)
is
begin
insert into machine_models (Machine_model) values (pMachineModel);
commit;
Exception when others then
pb_util.logdata(1, 'Admin_utilities.InsertMachineModel', 'Exception thrown', sqlerrm || ' stack ' || dbms_utility.format_error_backtrace);
rollback;
raise;
end;
What i believe to be the problem is this line in the web service:
cmd.Parameters.Add("pMachineModel", OracleType.Cursor).Value = Convert.ToString(MachineModel);
In my logger it says that a cursor must be implemented as a parameterdirection.output parameter however i do not believe in that case you can take a value and send it to the api, but if i am wrong feel free to correct me.
So i guess my question is: If what i believe to be correct in the statement above about parameterdirection is wrong, what is the correct answer?
Can anyone give me any suggestions as to how to implement what i am attempting to do correctly?
Any help or suggestions are greatly appreciated. Thank you.
I think your problem is in this line:
cmd.Parameters.Add("pMachineModel", OracleType.Cursor).Value =
Convert.ToString(MachineModel);
You're attempting to add a parameter of type OracleType.Cursor
, which isn't correct or necessary. Try changing the line to this:
cmd.Parameters.Add("pMachineModel", OracleType.Char).Value = MachineModel;
(There's also no need for Convert.ToString
here - MachineModel
is already a String
).
精彩评论