如何从Web服务在oracle过程中存储参数值

发布于 2024-12-08 11:32:37 字数 2087 浏览 0 评论 0原文

所以我想做的是使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心头的小情儿 2024-12-15 11:32:37

我认为您的问题出在这一行:

cmd.Parameters.Add("pMachineModel", OracleType.Cursor).Value = 
    Convert.ToString(MachineModel);

您正在尝试添加 OracleType.Cursor 类型的参数,这是不正确或不必要的。尝试将行更改为:(

cmd.Parameters.Add("pMachineModel", OracleType.Char).Value = MachineModel;

这里也不需要 Convert.ToString - MachineModel 已经是 String)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文