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

前端 未结 4 623
日久生厌
日久生厌 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:40

    I believe the easiest way to do this would be to add DB as a project to your solution. You can do this by right clicking on the DB in the SQL Server Object Explorer (SSOX). This is a really good way to develop and debug your DB's. After you have added the DB to your project, you can add breakpoints anywhere you want, and debug against LocalDB (or another target if you wish). The largest drawback to this approach is that your existing data will not migrate with you (although you will be able to easily publish any changes back to the SQL DB at will). See the documentation on SSDT on MSDN for further guidance.

    0 讨论(0)
  • 2020-12-09 18:47

    You need to open "SQL Server Object Explorer. Not "Server Explorer". That is what is different between 2010 & 2012. Then right click on the server and select "Application Debugging".

    0 讨论(0)
  • 2020-12-09 18:55

    The following in detail article explains exactly how to enable debugging of a Stored Procedure when a .Net application is executed.

    http://www.sqlmag.com/content1/topic/debugging-stored-procedures-142054/catpath/sql-server

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题