【问题标题】:SQL Server 2008 R2 Management Studio debugging: How to break at an exception?SQL Server 2008 R2 Management Studio 调试:如何中断异常?
【发布时间】:2013-05-20 18:26:13
【问题描述】:

在 Visual Studio 2008 中,无论是否有 catch 块,我都可以使用 CTRL+D+E 进行选择,让调试器在异常点中断。

SQL Server 2008 R2 Management Studio 中是否有类似的选项,其中存储过程执行将在引发错误时中断?

【问题讨论】:

    标签: sql-server-2008 debugging ssms


    【解决方案1】:

    在事务中使用 try 和 catch。例如:

    create proc procexmaple (@parameter int)
    as
        begin try
            begin transaction
                select  * from Employees where LastName = @parameter --this is an error converting nvarchar to int
            commit transaction
        end try
    
        begin catch
            select  * from [Orders] where OrderID = @parameter -- the catch will work and this will run
            rollback
        end catch
    go
    

    如果您想构建自己的错误,还可以查看如何使用 raiserror:

    https://www.sqlservertutorial.net/sql-server-stored-procedures/sql-server-raiserror/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多