如何从Web服务在oracle过程中存储参数值
所以我想做的是使用 Web 服务调用来实现 Oracle 程序。更具体地说:我的意思是,当我将一个值放入 Web 服务中的参数并运行它时,我希望该值成为发送到 Oracle 中的过程的值,然后在成功运行后返回到 Web 服务是真的。
我目前尝试的是:
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;
}
下面您将发现我的程序在 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;
我认为问题在于网络服务中的这一行:
cmd.Parameters.Add("pMachineModel", OracleType.Cursor).Value = Convert.ToString(MachineModel);
在我的记录器中,它说必须将光标实现为parameterdirection.output参数,但是我不相信在这种情况下您可以获取一个值并将其发送到api,但如果我错了,请随时纠正我。
所以我想我的问题是:如果我认为上面关于参数方向的陈述中正确的内容是错误的,那么正确的答案是什么?
任何人都可以给我任何关于如何正确实施我试图做的事情的建议吗?
非常感谢任何帮助或建议。谢谢。
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 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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您的问题出在这一行:
您正在尝试添加
OracleType.Cursor
类型的参数,这是不正确或不必要的。尝试将行更改为:(这里也不需要
Convert.ToString
-MachineModel
已经是String
)。I think your problem is in this line:
You're attempting to add a parameter of type
OracleType.Cursor
, which isn't correct or necessary. Try changing the line to this:(There's also no need for
Convert.ToString
here -MachineModel
is already aString
).