简体   繁体   English

无法附加到SQL Server以调试SQLCLR存储过程

[英]Can't attach to SQL Server to debug SQLCLR Stored Procedure

I want to debug a SQLCLR stored procedure in SQL Server. 我想在SQL Server中调试SQLCLR存储过程。 I have been trying to debug an SP in VS2015 Community and in the recently installed VS2017 Community editions without success. 我一直在尝试在VS2015社区和最近安装的VS2017社区版本中调试SP,但没有成功。 I am pretty sure that the problem lies in attaching to SQL Server but as I've done everything I can find mentioned online but to no avail. 我很确定问题在于附加到SQL Server,但因为我已经完成了我在网上提到的所有内容,但无济于事。

When creating the database project in SQL Server Express LocalDB everything works fine. 在SQL Server Express LocalDB中创建数据库项目时,一切正常。 If I change the connection string to use my Developer Edition SQL Server, I then get an error. 如果我更改连接字符串以使用我的Developer Edition SQL Server,那么我会收到错误。 I have done the following: 我做了以下事情:

  1. I created a new database. 我创建了一个新的数据库。 I am the only user of the server and it resides on the same desktop machine that I am using for Visual Studio. 我是服务器的唯一用户,它驻留在我用于Visual Studio的同一桌面计算机上。
  2. In Visual Studio I created a simple database project with a simple method to send some text to the output pipe. 在Visual Studio中,我使用一种简单的方法创建了一个简单的数据库项目,以便将一些文本发送到输出管道。

     [Microsoft.SqlServer.Server.SqlProcedure] public static void mytest () { SqlContext.Pipe.Send("in clr Craig1"); } 
  3. I edited the Target Connection String in the project properties to connect to the new database and successfully got a connection when pressing the connection button. 我在项目属性中编辑了目标连接字符串以连接到新数据库,并在按下连接按钮时成功建立连接。 The connection string used Windows Authentication for me, with the same user as the database owner. 连接字符串为我使用Windows身份验证,使用与数据库所有者相同的用户。
  4. I built and deployed the solution and checked the SQL Object Explorer to ensure that the SP was deployed. 我构建并部署了解决方案并检查了SQL对象资源管理器以确保部署了SP。 It was. 它是。
  5. I selected the server and, using the right click, selected the "Allow SQL/CLR Debugging". 我选择了服务器,然后使用右键单击选择“允许SQL / CLR调试”。 I checked it again to ensure it was actually set. 我再次检查它以确保它实际设置。
  6. I selected the stored procedure and with the right click, selected "Debug Procedure..." 我选择了存储过程并右键单击,选择“Debug Procedure ...”
  7. The debug script was displayed. 显示调试脚本。 I stepped to the line to exec the SP and then pressed F11 to step in. At this point I was shown the following: 我走到线上执行SP,然后按F11进入。此时我看到以下内容: 在此输入图像描述
  8. I pressed the attach and was shown the following error: 我按了附件,显示以下错误: 在此输入图像描述

Thereafter, the procedure executes and performs the pipe function, but it does not let me do the attachment and the debugging. 此后,该过程执行并执行管道功能,但它不允许我进行附件和调试。

Any ideas of what I'm doing wrong? 我做错了什么想法? Thanks Craig 谢谢克雷格

You might just need to start Visual Studio with "Run as Administrator". 您可能只需要使用“以管理员身份运行”启动Visual Studio。 I do not believe that I needed to do that when running Windows 8, but I am running Windows 10 now and definitely need to "Run as Administrator". 我不相信在运行Windows 8时我需要这样做,但我现在正在运行Windows 10并且肯定需要“以管理员身份运行”。 I am guessing that you cannot otherwise attach to someone else's process (I have my Developer Edition running with a service account of "SQL Server", yet LocalDB always runs as the Login that started it, typically yourself). 我猜你不能以其他方式附加到别人的进程(我的Developer Edition使用“SQL Server”服务帐户运行,但是LocalDB总是作为启动它的登录运行,通常是你自己)。 I have not tested to see if running Developer Edition as myself would still require "Run as Administrator", or how running Developer Edition as "Local System" would affect this behavior. 我没有测试过看看运行Developer Edition是否仍然需要“以管理员身份运行”,或者如何将Developer Edition作为“本地系统”运行会影响此行为。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM