迁移到 SQL Server 2012 后出现的 RAISERROR 问题 [英] RAISERROR issue since migration to SQL Server 2012

查看:40
本文介绍了迁移到 SQL Server 2012 后出现的 RAISERROR 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理服务器迁移后网站和数据库的一些问题.该数据库以前是 SQL Server Express 2005,但现在运行在 SQL Server Express 2012 上.

I am working on some issues with a website and database after a move of server. The database was previously SQL Server Express 2005 but is now running on SQL Server Express 2012.

问题与 RAISERROR 命令和 2012 年的更改有关.我查看了新语法的文档,但不确定如何将错误号和消息传递给网站.

The issues relate to the RAISERROR command and changes in 2012. I have looked at the documentation for the new syntax but am unsure on how I can pass both the error number and the message to the website.

存储过程和触发器中的 RAISERROR 命令的一些示例是:

Some examples of the RAISERROR commands in stored procedures and triggers are:

RAISERROR 50000 'Member with same Email address already exists.'

RAISERROR 44447 'The record can''t be added or changed. Referential integrity rules require a related record in table ''tblBrand''.'

RAISERROR 44446 'The record can''t be added or changed. Referential integrity rules require a related record in table ''tblFragranceHouse''.'

我已将一些更改为新语法,但不确定我是否正确执行此操作.我知道如果我只传递错误文本,它会传递错误号 50000.但我不确定如何处理其他错误代码.

I have changed some to the new syntax but am unsure if I have done this correctly or not. I understand that if I just pass the error text it passes error number 50000. But I'm not sure what to do about the other error codes.

关于如何将这些命令转换为 2012 的任何建议?

Any advice on how to translate these commands to 2012?

推荐答案

SQL 2012 不支持未记录版本的 Raiserror支持的语法是

SQL 2012 does not support the undocumented version of Raiserror The supported syntax is

RAISERROR(@Message,Serverity,state); 

-- @Message 可以是 message id ,但它应该存在于 sysmessages 中,所以如果你想发送自定义消息,我认为你应该添加它们 sysmessages

-- @Message could be message id , but it should exist in sysmessages, so if you want to send custom messages, I think you should add them sysmessages

http://msdn.microsoft.com/en-us/library/ms178592.aspx

或者另一种选择是使用 THROW

Or the other option is to use THROW

http://technet.microsoft.com/en-us/library/ee677615.aspx

这篇关于迁移到 SQL Server 2012 后出现的 RAISERROR 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆