Issues with T-SQL TRY CATCH?

前端 未结 5 700
野趣味
野趣味 2020-12-10 12:04

We are currently on SQL 2005 at work and I am migrating an old Foxpro system to new web application backed by SQL Server. I am using TRY CATCH in T-SQL for transaction proce

5条回答
  •  执笔经年
    2020-12-10 12:52

    TRY ... CATCH will fail to catch an error if you pass a "bad" search term to CONTAINSTABLE

    For example:

    DECLARE @WordList VARCHAR(800)
    SET @WordList = 'crap"s'
    CON
    
    TAINSTABLE(table, *, @WordList)
    

    The CONTAINSTABLE will give you a "syntax error", and any surrounding TRY ... CATCH does not catch this.

    This is particularly nasty because the error is caused by data, not by a "real" syntax error in your code.

提交回复
热议问题