从 cfstoredproc 访问 RAISEERROR 消息

发布于 2024-08-14 16:20:50 字数 505 浏览 2 评论 0原文

我有一个 SQL 存储过程,在某些情况下,如果失败,它会返回 -1 的结果,但也会通过 RAISERROR 命令返回一条消息,例如:

BEGIN

    RAISERROR ('Error %i has occurred', 11, 1, 0)
    RETURN -1

END

我使用 cfstoredproc 通过 Coldfusion 访问它,例如:

<cfstoredproc procedure="sp_return" datasource="myDatasource" returncode="yes">
<cfdump var="#cfstoredproc#">

但返回的结构仅包含 ExecutionTime和 StatusCode 键。有什么方法可以访问已返回的错误消息。例如显示给用户。

汤姆

谢谢 我会用“cfstoredproc”标记,但无法创建新标记。

I have a SQL stored procedure which under some situations will return a result of -1 if it fails, but also returns a message via the RAISERROR command e.g.:

BEGIN

    RAISERROR ('Error %i has occurred', 11, 1, 0)
    RETURN -1

END

I am accessing this via coldfusion using cfstoredproc e.g.:

<cfstoredproc procedure="sp_return" datasource="myDatasource" returncode="yes">
<cfdump var="#cfstoredproc#">

But the structure returned only contains an ExecutionTime and StatusCode keys. Is there any way I can access the error message which has been returned. e.g. To display to the user.

Thanks,

Tom

p.s. I would tag with "cfstoredproc" but I can't create new tags.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

始终不够 2024-08-21 16:20:50

不确定您使用什么数据库,但对于 Oracle,我只是使用 ColdFusion 异常来冒泡 Oracle 异常。 - #cfcatch.message# 和 #cfcatch.detail# 是您想要向用户回显的内容。

<cftry>

<cfstoredproc  procedure = "my_Proc" dataSource = "#DB#" returnCode = "No">
   <cfprocparam type="in" cfsqltype="CF_SQL_VARCHAR" variable="myvar"   value="#someval#" null="No"> 
   <cfprocresult name="my_Response">
</cfstoredproc>

<cfcatch type="any">

   <cflog file="ProcError" text="Message = #cfcatch.message# Detail= #cfcatch.detail#">

</cfcatch>
</cftry>

Not sure what DB you use but with Oracle I just use ColdFusion Exceptions to bubble up the Oracle exceptions. - #cfcatch.message# and #cfcatch.detail# are what you want to echo to the user.

<cftry>

<cfstoredproc  procedure = "my_Proc" dataSource = "#DB#" returnCode = "No">
   <cfprocparam type="in" cfsqltype="CF_SQL_VARCHAR" variable="myvar"   value="#someval#" null="No"> 
   <cfprocresult name="my_Response">
</cfstoredproc>

<cfcatch type="any">

   <cflog file="ProcError" text="Message = #cfcatch.message# Detail= #cfcatch.detail#">

</cfcatch>
</cftry>
瀟灑尐姊 2024-08-21 16:20:50

您尝试过cfprocresult吗? 手册页说:

将查询对象与
存储返回的结果集
程序。

Have you tried cfprocresult? Manual page says:

Associates a query object with a
result set returned by a stored
procedure.

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