简体   繁体   中英

try catch not working in 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

Error:

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.

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

the reason for a such error is seems to be the target database is running on a MS SQL Server 2000 server. So be sure that your database server is SQL2005

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

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

the reason for a such error is seems to be the target database is running on a MS SQL Server 2000 server. So be sure that your database server is SQL2005

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM