SQL Server 2005-Error_Message()未显示完整消息 [英] SQL Server 2005 - Error_Message() not showing full message

查看:479
本文介绍了SQL Server 2005-Error_Message()未显示完整消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试/捕获中封装了一个备份数据库命令,看来错误消息在某处丢失了。例如:

I have encapsulated a backup database command in a Try/Catch and it appears that the error message is being lost somewhere. For example:

BACKUP DATABASE NonExistantDB TO DISK = 'C:\TEMP\NonExistantDB.bak'

.. gives错误:

无法在sysdatabases中找到数据库条目'NonExistantDB'。找不到使用该名称的条目。确保正确输入名称。备份数据库异常终止。

..gives error:
Could not locate entry in sysdatabases for database 'NonExistantDB'. No entry found with that name. Make sure that the name is entered correctly. BACKUP DATABASE is terminating abnormally.

其中:

BEGIN TRY
    BACKUP DATABASE NonExistantDB TO DISK = 'C:\TEMP\NonExistantDB.bak'
END TRY
BEGIN CATCH
    PRINT ERROR_MESSAGE()
END CATCH

...仅给出错误: BACKUP DATABASE is

... only gives error: BACKUP DATABASE is terminating abnormally.

是否可以获取完整的错误消息,或者这是try / catch的限制?

Is there a way to get the full error message or is this a limitation of try/catch?

推荐答案

这是try / catch的限制。

It's a limitation of try/catch.

如果您仔细看一下执行

 BACKUP DATABASE NonExistantDB TO DISK = 'C:\TEMP\NonExistantDB.bak'

您会发现有两个错误被抛出。第一个是味精911,它指出

you'll find that there are two errors that get thrown. The first is msg 911, which states


无法在sysdatabases中找到数据库 NonExistantDB的条目。找不到该名称的条目
。确保正确输入名称。

Could not locate entry in sysdatabases for database 'NonExistantDB'. No entry found with that name. Make sure that the name is entered correctly.

第二个是您正在显示的3013消息。基本上,SQL只返回最后一个错误。

The second is the 3013 message that you are displaying. Basically, SQL is only returning the last error.

这篇关于SQL Server 2005-Error_Message()未显示完整消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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