How to debug SQL Server T-SQL in Visual Studio 2012

前端 未结 4 624
日久生厌
日久生厌 2020-12-09 18:02

How does one debug a T-SQL stored procedure in a multi-tier application in Visual Studio 2012?

To be clear, I want to set a breakpoint in a sproc in VS 2012, and hi

4条回答
  •  醉梦人生
    2020-12-09 18:56

    This is for VS2012 and SQL2012. Yes things are somewhat different for other versions, but kinda follow similar setup. It is tricky because one has to have various settings just right or it won't work.

    • vanilla install of both VS and SQL with all correct options (how to do this is outside scope of this article)

    • full admin rights to entire environment and sysadmin rights to sql (fundamentally a development environment; you would not want to do this in a production environment)

    • i always debug .net web apps under full local IIS which is a windows feature installed from control panel

      • go .net project properties, web, use local iis web server (i also stick to default port 80)
    • while i develop my databases etc using VS sql server database project, i always work under full standalone local SQL; i use the schema compare to refresh that sql with changes made in VS (how to do this is outside scope of this article)

      • do not place your breakpoint on that copy of the sp; that version of the sp is only a blueprint and not the runtime version
    • go .net project properties, web, debuggers (at bottom) enabled for .net and sql server

    • view sql server object explorer (not server explorer)

      • click add sql server, add your full local sql server using sysadmin credentials (i always use sa for such work)
      • right click on your full local sql server and enable application debugging
      • there go find the sp and right click and view code, then add your breakpoint there; this is runtime version of sp (note that i never make changes to sp there, i go do these in my master copy under the database project)
    • rebuild solution, and execute .net web app in debug mode from within ide by clicking green arrow internet explorer

    I hope I have not forgotten anything. If I have I'll come revised my post.

    All this may sound complicated. It is. But with a little discipline and patience it is priceless. Good luck.

提交回复
热议问题