简体   繁体   English

如何从C#代码进入SQL Server存储过程?

[英]How can I step into a SQL Server stored proc from my C# code?

I am debugging some C# code that uses Ado.net to call a stored proc (TSQL) in SQL Server. 我正在调试一些使用Ado.net在SQL Server中调用存储过程(TSQL)的C#代码。 How can I step into the stored proc? 我怎样才能进入存储过程?

(I think I have seen this demoed by Microsoft staff, but can't recall the 101 “magic” settings that are needed to get it to work.) (我想我已经看过微软工作人员演示的这个,但是不记得让它工作所需的101个“神奇”设置。)

I'll build on Davide's answer and Ian's comment to it because that was the exactly the process I have gone through. 我将以Davide的回答和Ian对它的评论为基础,因为这正是我经历的过程。

Assumption : answer is based on VS2008 & VS2010 . 假设 :答案基于VS2008和VS2010

To step through a T-SQL stored procedure on SQL Server while debugging a .NET app you need to do the following: 要在调试.NET应用程序时在SQL Server上单步执行T-SQL存储过程,您需要执行以下操作:

  1. Follow the MS Support instructions " How to debug stored procedures in Visual Studio .NET (Option 2) " 按照MS支持说明“ 如何在Visual Studio .NET中调试存储过程 (选项2)

    • Ensure that you have enabled SQL Server debugging in the project's properties (Step 4 in the linked instructions). 确保已在项目的属性中启用SQL Server调试 (链接指令中的步骤4)。
    • Ensure you have set a breakpoint in the stored procedure itself (Steps 6-7) 确保在存储过程本身中设置了断点 (步骤6-7)
  2. Enable the Allow SQL/CLR Debugging on the Data Connection on which the stored procedure is called: 在调用存储过程的数据连接上启用“ 允许SQL / CLR调试 ”:

    • (without this second step you'll be getting "The breakpoint will not currently be hit. Unable to bind SQL breakponit at this time. Object containing the breakpoint not loaded." as reported by Ian) (没有第二步,你将得到“断点当前不会被命中。此时无法绑定SQL breakponit。包含未加载断点的对象。”由Ian报告)
    • Server Explorer > Data Connections Server Explorer >数据连接
    • Right-click on the connection that you are using in the code 右键单击您在代码中使用的连接
    • Tick the Allow SQL/CLR Debugging option in the menu 勾选菜单中的Allow SQL / CLR Debugging选项

Added from comments: (This seem to be key to getting it to work) 从评论中添加:(这似乎是让它工作的关键)

It works with a programmatically created connection, too. 它也适用于以编程方式创建的连接。 You just have to use the exact same connection string that is displayed when you right-click the server instance, click on 'Properties' and scroll down to 'Connection string' (Verbindungszeichenfolge in German). 您只需使用右键单击服务器实例时显示的完全相同的连接字符串 ,单击“属性”并向下滚动到“连接字符串”(德语中的Verbindungszeichenfolge)。

For those of you who are using VS 2012 and are confused as to why you cannot enable SQL/CLR Debugging from the Server Explorer window, you actually need to connect via the "SQL Server Object Explorer" window. 对于那些使用VS 2012并且对于为什么无法从“服务器资源管理器”窗口启用SQL / CLR调试感到困惑的人,实际上需要通过“SQL Server对象资源管理器”窗口进行连接。

Once you have the connection in that window, the Allow SQL/CLR Debugging and Application Debugging setting appear on the right-click context menu of your server. 在该窗口中建立连接后,将在服务器的右键单击上下文菜单中显示“ Allow SQL/CLR DebuggingApplication Debugging设置。 This probably applies to 2013 as well but I cannot confirm. 这可能也适用于2013年,但我无法确认。

在项目属性中启用SQL Server调试。

In Solution Explorer, right-click the project (not the solution) and open the Property pages. 在解决方案资源管理器中,右键单击项目(而不是解决方案)并打开“属性”页面。 Click Configuration Properties in the tree and then click to select the SQL Server Debugging check box on the Debugging page to enable stored procedure debugging. 单击树中的“配置属性”,然后单击以选中“调试”页面上的“SQL Server调试”复选框以启用存储过程调试。

reference: http://support.microsoft.com/kb/316549 参考: http//support.microsoft.com/kb/316549

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#和SQL Server:如何通过使用C#调用存储过程来从SQL表中获取值? - C# and SQL Server: How do I get values from my SQL Table, by calling my stored procedure with C#? 如何使用C#代码为SQL Server创建存储过程? - How To create a stored procedure for SQL Server from C# code? 从 sql 存储过程加载和调用 C#(程序集) - loading and calling C# (assembly) from a sql stored proc 我可以在SQL Server存储过程中转换字符编码吗? - Can I convert character encodings in an SQL Server stored proc? 如何从 C# 代码确定存储在 SQL Server 中的按位代码值 - How to determine bitwise code value stored in SQL Server from C# code 从C#代码调用SQL Server存储过程时出错 - Error calling SQL Server stored procedure from C# code 如何确保C#应用程序只能从SQL Server数据库读取? - How can I ensure that my C# application can only read from the SQL Server databases? 如何检查我是否有来自 SQL 服务器数据库的图像或不使用 C# - How can I check if I have an image from my SQL Server database or not using C# 我可以将此C#逻辑转换为SQL SERVER存储过程吗? - Can i convert this C# logic into SQL SERVER stored procedure? 如何在SQL Server中创建存储过程并通过C#代码使用该过程的一些参数从该过程中调用该过程 - How to create stored procedure in sql server and call that procedure from C# code behind with some parameters to that procedure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM