SSDT SQL Server Debugging Doesn't Hit CLR Breakpoints

China☆狼群 提交于 2019-12-03 02:49:17
Buggieboy

Okay, I finally figured this out. To debug SQL CLR code in VS 2012:

  1. Create a SQL test script that calls the UDF, sproc, or other CLR object. (You can do this by using the "Execute Function" or "Debug Function" options in the Server Object Explorer, as described in the question.)

  2. Save the generated script. (It will be called something like "SQLQuery1.sql" by default. You may wish to give it a more meaningful name.)

  3. In Solution Explorer, right-click the UDF (or other CLR type) project, and select "Properties".

  4. The project's properties tab will open. On the left, select the "Debug" category.

  5. In the "Start Action" subcategory of the Debug panel, select the "Startup script:" radio button. This will enable the associated dropdown so that you can specify the .sql script created in Step 1.

  6. Save all, toggle a breakpoint on an executable line of your C# or other .NET language code, and press the debug button.

NOTE: You may now get a dialog telling you that "Windows Firewall has blocked some features of this program." I checked the boxes to allow access to domain and private networks.

Proceeding now should cause your breakpoint to be reached.

For Visual Studio 2015 + Update 2:

In SQL Server Object Explorer pane, right-click on the server and select "Allow SQL/CLR Debugging":

In Server Explorer, right click on the function you want to debug, and select Execute:

It will generate the code for you. Select Execute with Debugger:

You can then place a breakpoint in your C# code, and it will hit it.

It will ask to open a port in your firewall, and it will ask to attach to SQL Server.

I do not know if SSDT changes this, but in VS2008 I debug a .net UDF as follows:

  • I deploy it to my local SQL server,
  • then I attach VS to the SQL Server process (Menu Debug/Attach to process/sqlserver.exe, if SQL Server is running as a service it requires that VS was started as administrator).
  • Then execute some SQL code calling the UDF, e. g. in Management Studio. Maybe this will work from SSDT in VS 2012.

The patch you applied may install VS items which are not current with the Visual Studio Quarterly update. I recommend that you now apply the latest Visual Studio Quarterly Update for VS 2012.

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