本文介绍了无法连接到SQL Server来调试SQLCLR存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在SQL Server中调试SQLCLR存储过程.我一直在尝试在VS2015社区和最近安装的VS2017社区版本中调试SP,但未成功.我很确定问题出在附加到SQL Server上,但是当我完成所有可以在网上找到的内容时,却无济于事.

I want to debug a SQLCLR stored procedure in SQL Server. I have been trying to debug an SP in VS2015 Community and in the recently installed VS2017 Community editions without success. 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 Express LocalDB中创建数据库项目时,一切正常.如果我更改连接字符串以使用我的Developer Edition SQL Server,则会收到错误消息.我已经做了以下事情:

When creating the database project in SQL Server Express LocalDB everything works fine. If I change the connection string to use my Developer Edition SQL Server, I then get an error. I have done the following:

  1. 我创建了一个新数据库.我是服务器的唯一用户,它驻留在我用于Visual Studio的同一台台式机上.
  2. 在Visual Studio中,我使用简单的方法创建了一个简单的数据库项目,该方法将一些文本发送到输出管道.

  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.
  2. In Visual Studio I created a simple database project with a simple method to send some text to the output pipe.

[Microsoft.SqlServer.Server.SqlProcedure]
public static void mytest ()
{
    SqlContext.Pipe.Send("in clr Craig1");
}

  • 我在项目属性中编辑了目标连接字符串以连接到新数据库,并在按下连接按钮时成功建立了连接.连接字符串对我使用Windows身份验证,并且与数据库所有者使用同一用户.
  • 我构建并部署了解决方案,并检查了SQL Object Explorer,以确保已部署SP.是.
  • 我选择了服务器,然后右键单击选择了允许SQL/CLR调试".我再次检查了一下以确保它已经设置好.
  • 我选择了存储过程,然后单击鼠标右键,选择调试过程..."
  • 已显示调试脚本.我走到执行SP的那一行,然后按F11进入.在这一点上,我看到以下内容:
  • 我按了附件,并显示以下错误:
  • 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.
  • I built and deployed the solution and checked the SQL Object Explorer to ensure that the SP was deployed. It was.
  • I selected the server and, using the right click, selected the "Allow SQL/CLR Debugging". I checked it again to ensure it was actually set.
  • I selected the stored procedure and with the right click, selected "Debug Procedure..."
  • 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:
  • 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?ThanksCraig

    推荐答案

    您可能只需要使用以管理员身份运行"启动Visual Studio.我不认为在运行Windows 8时需要这样做,但是我现在在运行Windows 10,并且绝对需要以管理员身份运行".我猜想您不能以其他方式附加到其他人的进程中(我的开发人员版运行的服务帐户为"SQL Server",但LocalDB始终作为启动它的登录名运行,通常是您自己).我尚未测试过以自己的身份运行Developer Edition是否仍然需要以管理员身份运行",或者以本地系统"身份运行Developer Edition会如何影响此行为.

    You might just need to start Visual Studio with "Run as Administrator". 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". 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). 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.

    这篇关于无法连接到SQL Server来调试SQLCLR存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    08-18 18:27