尝试 catch 在 sql server 2005 中不起作用 [英] try catch not working in sql server 2005

查看:46
本文介绍了尝试 catch 在 sql server 2005 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我尝试在 sql server 2005 中运行以下代码,我会收到错误

if i try to run following code in sql server 2005 i get error

BEGIN TRY

        SELECT 1/0;
    END TRY
    BEGIN CATCH
        SELECT
            ERROR_NUMBER() AS ErrorNumber
            ,ERROR_SEVERITY() AS ErrorSeverity
            ,ERROR_STATE() AS ErrorState
            ,ERROR_PROCEDURE() AS ErrorProcedure
            ,ERROR_LINE() AS ErrorLine
            ,ERROR_MESSAGE() AS ErrorMessage;
    END CATCH;
    GO

错误:

Line 1: Incorrect syntax near 'TRY'.
Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'END'.
Msg 195, Level 15, State 10, Line 7
'ERROR_NUMBER' is not a recognized function name.

我使用的是 sql server 2000 服务管理器,但现在我已经安装了 sql server 2005 服务管理器,但仍然出现错误..与它相关的一篇文章说

i was using sql server 2000 service manager but now i have installed sql server 2005 service manager but still get the error..one article related to it says

出现此类错误的原因似乎是目标数据库在 MS SQL Server 2000 服务器上运行.所以一定要确定你的数据库服务器是SQL2005

这是什么意思...?我必须做哪些改变???

what does it mean..?what changes i have to do???

推荐答案

您需要使用 SQL Server 2005 或更高版本才能使用 TRY...CATCH,如果您仍然使用 SQL Server Management Studio,安装 SQL Server Management Studio 将无济于事连接到 SQL 2000 服务器.

You need to be using SQL Server 2005 or above to be able to use TRY...CATCH, installing SQL Server Management Studio will not help if you are still connecting to a SQL 2000 server.

这篇关于尝试 catch 在 sql server 2005 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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