[英]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. 所以我要做的是使用Web服务调用来实现oracle过程。 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.
更具体一点:我是这样的,当我将一个值放入我的Web服务中的参数并运行它时,我希望它是发送到oracle中的过程的值,然后成功运行后返回到Web服务是的。
What i have currently tried to to is this: 我目前试图达到的目的是:
public bool InsertMachineModels(string MachineModel)
{
logger.DebugFormat("FilteredReportInputsDAO.InsertMachineModel({0})", MachineModel);
bool retVal = 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. 下面你会发现我的程序在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: 我认为问题在于Web服务中的这一行:
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. 在我的记录器中它表示游标必须实现为parameterdirection.output参数但是我不相信在这种情况下你可以获取一个值并将其发送到api,但如果我错了,请随意纠正我。
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. 您正在尝试添加
OracleType.Cursor
类型的参数,这是不正确或必要的。 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
). (此处也不需要
Convert.ToString
- MachineModel
已经是一个String
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.