try catch not working in sql server 2005

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 16:54:46

问题


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???


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/1810032/try-catch-not-working-in-sql-server-2005

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!