运行 TSQL 调试器之前配置防火墙规则Configure firewall rules before running the TSQL Debugger

本主题适用于:是SQL Server是Azure SQL 数据库是Azure SQL 数据仓库是并行数据仓库THIS TOPIC APPLIES TO: yesSQL ServeryesAzure SQL DatabaseyesAzure SQL Data Warehouse yesParallel Data Warehouse

必须配置 Windows 防火墙规则,以便在连接到 Transact-SQLTransact-SQL实例(运行该实例的计算机不同于运行 数据库引擎Database Engine查询编辑器的计算机)时启用 数据库引擎Database Engine 调试。Windows Firewall rules must be configured to enable Transact-SQLTransact-SQL debugging when connected to an instance of the 数据库引擎Database Engine that is running on a different computer than the 数据库引擎Database Engine Query Editor.

配置 Transact-SQL 调试器Configuring the Transact-SQL Debugger

Transact-SQLTransact-SQL 调试器包括服务器端和客户端组件。The Transact-SQLTransact-SQL debugger includes both server-side and client-side components. 服务器端调试器组件与 SQL Server 2005SQL Server 2005 Service Pack 2 (SP2) 或更高版本中的每个数据库引擎实例一起安装。The server-side debugger components are installed with each instance of the Database Engine from SQL Server 2005SQL Server 2005 Service Pack 2 (SP2) or later. 包括客户端调试器组件:The client-side debugger components are included:

  • 在从 SQL Server 2008SQL Server 2008 或更高版本安装客户端工具时。When you install the client-side tools from SQL Server 2008SQL Server 2008 or later.

  • 在安装 Microsoft Visual Studio 2010 或更高版本时。When you install Microsoft Visual Studio 2010 or later.

  • 在从 Web 下载安装 SQL Server Data Tools (SSDT)SQL Server Data Tools (SSDT) 时。When you install SQL Server Data Tools (SSDT)SQL Server Data Tools (SSDT) from the web download.

    如果 Transact-SQLTransact-SQLSQL Server Management StudioSQL Server Management StudioSQL Server Data ToolsSQL Server Data Tools 实例在同一台计算机上运行,则对于运行 SQL Server 数据库引擎SQL Server Database Engine调试器没有配置要求。There are no configuration requirements to run the Transact-SQLTransact-SQL debugger when SQL Server Management StudioSQL Server Management Studio or SQL Server Data ToolsSQL Server Data Tools is running on the same computer as the instance of the SQL Server 数据库引擎SQL Server Database Engine. 但是,要在 Transact-SQLTransact-SQL 调试器连接到 数据库引擎Database Engine的远程实例时运行此调试器,必须在两台计算机上的 Windows 防火墙中启用程序和端口规则。However, to run the Transact-SQLTransact-SQL debugger when connected to a remote instance of the 数据库引擎Database Engine, program and port rules in the Windows Firewall must be enabled on both computers. 这些规则可通过 SQL ServerSQL Server 安装程序创建。These rules may be created by SQL ServerSQL Server setup. 如果您在尝试打开远程调试会话时系统显示错误,则请确保在您的计算机上定义以下防火墙规则。If you get errors attempting to open a remote debugging session, ensure the following firewall rules are defined on your computer.

    使用 “高级安全 Windows 防火墙” 应用程序管理防火墙规则。Use the Windows Firewall with Advanced Security application to manage the firewall rules. Windows 7Windows 7Windows Server 2008 R2Windows Server 2008 R2中,打开 “控制面板”,打开 “Windows 防火墙”,然后选择 “高级设置”In both Windows 7Windows 7 and Windows Server 2008 R2Windows Server 2008 R2, open Control Panel, open Windows Firewall, and select Advanced settings. Windows Server 2008 R2Windows Server 2008 R2 中,您还可以打开 “服务管理器”,在左侧的窗格中展开 “配置” ,然后展开 “高级安全 Windows 防火墙”In Windows Server 2008 R2Windows Server 2008 R2 you can also open Service Manager, expand Configuration in the left pane, and expand Windows Firewall with Advanced Security.

小心

在“Windows 防火墙”中启用规则可能会导致您的计算机暴露在防火墙在设计上可以阻止的安全风险之中。Enabling rules in the Windows Firewall may expose your computer to security threats that the firewall is designed to block. 为远程调试启用规则将取消阻止在本主题中列出的端口和程序。Enabling rules for remote debugging unblocks the ports and programs listed in this topic.

服务器上的防火墙规则Firewall Rules on the Server

在运行 数据库引擎Database Engine实例的计算机上,使用 “高级安全 Windows 防火墙” 可以指定以下信息:On the computer that is running the instance of the 数据库引擎Database Engine, use Windows Firewall with Advanced Security to specify the following information:

  • 为 sqlservr.exe 添加入站程序规则。Add an inbound program rule for sqlservr.exe. 对于需要支持远程调试会话的每个实例,您必须具有一个规则。You must have a rule for each instance that needs to support remote debugging sessions.

    1. 在“高级安全 Windows 防火墙”的左窗格中,右键单击“入站规则”,然后在操作窗格中选择“新建规则”。In Windows Firewall with Advanced Security, in the left pane, right-click Inbound Rules, and then select New Rule in the action pane.

    2. “规则类型” 对话框中,选择 “程序”,然后单击 “下一步”In the Rule Type dialog, select Program, and then click Next.

    3. “程序” 对话框中,选择 “此程序路径:” ,然后输入指向此实例的 sqlservr.exe 的完整路径。In the Program dialog, select This program path: and enter the full path to sqlservr.exe for this instance. 默认情况下,sqlservr.exe 安装在 C:\Program Files\Microsoft SQL Server\MSSQL13.InstanceName\MSSQL\Binn 中,其中, InstanceName 对于默认实例为 MSSQLSERVER,对于任何指定的实例则为相应实例的名称。By default, sqlservr.exe is installed in C:\Program Files\Microsoft SQL Server\MSSQL13.InstanceName\MSSQL\Binn, where InstanceName is MSSQLSERVER for the default instance, and the instance name for any named instance.

    4. “操作” 对话框中,选择 “允许连接”,然后单击 “下一步”In the Action dialog, select Allow the connection, and click Next.

    5. “配置文件” 对话框中,选择在您想要打开针对该实例的调试会话时描述计算机连接环境的任何配置文件,然后单击 “下一步”In the Profile dialog, select any profiles that describe the computer connection environment when you want to open a debugging session with the instance, and click Next.

    6. “名称” 对话框中,键入针对此规则的名称和说明,然后单击 “完成”In the Name dialog, type a name and description for this rule and click Finish.

    7. “入站规则” 列表中,右键单击您创建的规则,然后在操作窗格中选择 “属性”In the Inbound Rules list, right click the rule you created, and then select Properties in the action pane.

    8. 选择 “协议和端口” 选项卡。Select the Protocols and Ports tab.

    9. “协议类型:” 框中选择 “TCP” ,在 “本地端口:” 框中选择 “RPC 动态端口” ,单击 “应用”,然后单击 “确定”Select TCP in the Protocol type: box, select RPC Dynamic Ports in the Local port: box, click Apply, and then click OK.

  • 添加针对 svchost.exe 的入站程序规则,以便启用从远程调试器会话的 DCOM 通信。Add an inbound program rule for svchost.exe to enable DCOM communications from remote debugger sessions.

    1. 在“高级安全 Windows 防火墙”的左窗格中,右键单击“入站规则”,然后在操作窗格中选择“新建规则”。In Windows Firewall with Advanced Security, in the left pane, right-click Inbound Rules, and then select New Rule in the action pane.

    2. “规则类型” 对话框中,选择 “程序”,然后单击 “下一步”In the Rule Type dialog, select Program, and then click Next.

    3. “程序” 对话框中,选择 “此程序路径:” ,然后输入指向 svchost.exe 的完整路径。In the Program dialog, select This program path: and enter the full path to svchost.exe. 默认情况下,svchost.exe 安装在 %systemroot%\System32\svchost.exe 中。By default, svchost.exe is installed in %systemroot%\System32\svchost.exe.

    4. “操作” 对话框中,选择 “允许连接”,然后单击 “下一步”In the Action dialog, select Allow the connection, and click Next.

    5. “配置文件” 对话框中,选择在您想要打开针对该实例的调试会话时描述计算机连接环境的任何配置文件,然后单击 “下一步”In the Profile dialog, select any profiles that describe the computer connection environment when you want to open a debugging session with the instance, and click Next.

    6. “名称” 对话框中,键入针对此规则的名称和说明,然后单击 “完成”In the Name dialog, type a name and description for this rule and click Finish.

    7. “入站规则” 列表中,右键单击您创建的规则,然后在操作窗格中选择 “属性”In the Inbound Rules list, right click the rule you created, and then select Properties in the action pane.

    8. 选择 “协议和端口” 选项卡。Select the Protocols and Ports tab.

    9. “协议类型:” 框中选择 “TCP” ,在 “本地端口:” 框中选择 “RPC 端点映射程序” ,单击 “应用”,然后单击 “确定”Select TCP in the Protocol type: box, select RPC Endpoint Mapper in the Local port: box, click Apply, and then click OK.

  • 如果域策略要求通过 IPSec 进行网络通信,还必须添加打开 UDP 端口 4500 和 UDP 端口 500 的入站规则。If the domain policy requires network communications to be done through IPsec, you must also add inbound rules opening UDP port 4500 and UDP port 500.

客户端上的防火墙规则Firewall Rules on the Client

在正运行 数据库引擎Database Engine 查询编辑器的计算机上,SQL Server 安装程序或 SQL Server Data ToolsSQL Server Data Tools 安装程序可能已将 Windows 防火墙配置为允许远程调试。On the computer that is running the 数据库引擎Database Engine Query Editor, the SQL Server setup or SQL Server Data ToolsSQL Server Data Tools setup may have configured the Windows Firewall to allow remote debugging.

如果您在尝试打开远程调试会话时系统显示错误,则可以通过使用 “高级安全 Windows 防火墙” 配置防火墙规则来手动配置程序和端口例外:If you get errors attempting to open a remote debugging session, you can manually configure the program and port exceptions by using Windows Firewall with Advanced Security to configure firewall rules:

  • 为 svchost 添加程序条目:Add a program entry for svchost:

    1. 在“高级安全 Windows 防火墙”的左窗格中,右键单击“入站规则”,然后在操作窗格中选择“新建规则”。In Windows Firewall with Advanced Security, in the left pane, right-click Inbound Rules, and then select New Rule in the action pane.

    2. “规则类型” 对话框中,选择 “程序”,然后单击 “下一步”In the Rule Type dialog, select Program, and then click Next.

    3. “程序” 对话框中,选择 “此程序路径:” ,然后输入指向 svchost.exe 的完整路径。In the Program dialog, select This program path: and enter the full path to svchost.exe. 默认情况下,svchost.exe 安装在 %systemroot%\System32\svchost.exe 中。By default, svchost.exe is installed in %systemroot%\System32\svchost.exe.

    4. “操作” 对话框中,选择 “允许连接”,然后单击 “下一步”In the Action dialog, select Allow the connection, and click Next.

    5. “配置文件” 对话框中,选择在您想要打开针对该实例的调试会话时描述计算机连接环境的任何配置文件,然后单击 “下一步”In the Profile dialog, select any profiles that describe the computer connection environment when you want to open a debugging session with the instance, and click Next.

    6. “名称” 对话框中,键入针对此规则的名称和说明,然后单击 “完成”In the Name dialog, type a name and description for this rule and click Finish.

    7. “入站规则” 列表中,右键单击您创建的规则,然后在操作窗格中选择 “属性”In the Inbound Rules list, right click the rule you created, and then select Properties in the action pane.

    8. 选择 “协议和端口” 选项卡。Select the Protocols and Ports tab.

    9. “协议类型:” 框中选择 “TCP” ,在 “本地端口:” 框中选择 “RPC 端点映射程序” ,单击 “应用”,然后单击 “确定”Select TCP in the Protocol type: box, select RPC Endpoint Mapper in the Local port: box, click Apply, and then click OK.

  • 为承载 数据库引擎Database Engine 查询编辑器的应用程序添加程序条目。Add a program entry for the application hosting the 数据库引擎Database Engine Query Editor. 如果您需要在同一台计算机上从 SQL Server Management StudioSQL Server Management StudioSQL Server Data ToolsSQL Server Data Tools 都打开远程调试会话,则必须为这两者都添加一个程序规则:If you need to open remote debugging sessions from both SQL Server Management StudioSQL Server Management Studio and SQL Server Data ToolsSQL Server Data Tools on the same computer, you must add a program rule for both:

    1. 在“高级安全 Windows 防火墙”的左窗格中,右键单击“入站规则”,然后在操作窗格中选择“新建规则”。In Windows Firewall with Advanced Security, in the left pane, right-click Inbound Rules, and then select New Rule in the action pane.

    2. “规则类型” 对话框中,选择 “程序”,然后单击 “下一步”In the Rule Type dialog, select Program, and then click Next.

    3. “程序” 对话框中,选择 “此程序路径:” ,然后输入以下三个值之一。In the Program dialog, select This program path: and enter one of these three values.

      • 对于 SQL Server Management StudioSQL Server Management Studio,输入指向 ssms.exe 的完整路径。For SQL Server Management StudioSQL Server Management Studio, enter the full path to ssms.exe. 默认情况下,ssms.exe 安装在 C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\Management Studio 下。By default, ssms.exe is installed in C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\Management Studio.

      • 对于 SQL Server Data ToolsSQL Server Data Tools ,输入指向 devenv.exe 的完整路径:For SQL Server Data ToolsSQL Server Data Tools enter the full path to devenv.exe:

        1. 默认情况下,针对 Visual Studio 2010 的 devenv.exe 位于 C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE 中。By default, the devenv.exe for Visual Studio 2010 is in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE.

        2. 默认情况下,针对 Visual Studio 2012 的 devenv.exe 位于 C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE 中。By default, the devenv.exe for Visual Studio 2012 is in C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE

        3. 您可以从用来启动 SQL Server Management StudioSQL Server Management Studio的快捷方式中找到指向 ssms.exe 的路径。You can find the path to ssms.exe from the shortcut you use to launch SQL Server Management StudioSQL Server Management Studio. 您可以从用来启动 SQL Server Data ToolsSQL Server Data Tools的快捷方式中找到指向 devenv.exe 的路径。You can find the path to devenv.exe from the shortcut you use to launch SQL Server Data ToolsSQL Server Data Tools. 右键单击该快捷方式并选择 “属性”Right click the shortcut and select Properties. 可执行文件和路径将在 “目标” 框中列出。The executable and path are listed in the Target box.

    4. “操作” 对话框中,选择 “允许连接”,然后单击 “下一步”In the Action dialog, select Allow the connection, and click Next.

    5. “配置文件” 对话框中,选择在您想要打开针对该实例的调试会话时描述计算机连接环境的任何配置文件,然后单击 “下一步”In the Profile dialog, select any profiles that describe the computer connection environment when you want to open a debugging session with the instance, and click Next.

    6. “名称” 对话框中,键入针对此规则的名称和说明,然后单击 “完成”In the Name dialog, type a name and description for this rule and click Finish.

    7. “入站规则” 列表中,右键单击您创建的规则,然后在操作窗格中选择 “属性”In the Inbound Rules list, right click the rule you created, and then select Properties in the action pane.

    8. 选择 “协议和端口” 选项卡。Select the Protocols and Ports tab.

    9. “协议类型:” 框中选择 “TCP” ,在 “本地端口:” 框中选择 “RPC 动态端口” ,单击 “应用”,然后单击 “确定”Select TCP in the Protocol type: box, select RPC Dynamic Ports in the Local port: box, click Apply, and then click OK.

启动调试器的要求Requirements for Starting the Debugger

启动 Transact-SQLTransact-SQL 调试器的所有尝试还必须满足以下要求:All attempts to start the Transact-SQLTransact-SQL debugger must also meet the following requirements:

  • SQL Server Management StudioSQL Server Management StudioSQL Server Data ToolsSQL Server Data Tools 必须在作为 sysadmin 固定服务器角色成员的 Windows 帐户下运行。 or SQL Server Data ToolsSQL Server Data Tools must be running under a Windows account that is a member of the sysadmin fixed server roll.

  • 数据库引擎Database Engine 查询编辑器窗口必须使用 Windows 身份验证来连接,或使用作为 sysadmin 固定服务器角色成员的 SQL ServerSQL Server 身份验证登录名来连接。The 数据库引擎Database Engine Query Editor window must be connected by using either a Windows Authentication or SQL ServerSQL Server Authentication login that is a member of the sysadmin fixed server role.

  • 数据库引擎Database Engine 查询编辑器窗口必须从 数据库引擎Database Engine Service Pack 2 (SP2) 或更高版本连接到 SQL Server 2005SQL Server 2005 实例。The 数据库引擎Database Engine Query Editor window must be connected to an instance of the 数据库引擎Database Engine from SQL Server 2005SQL Server 2005 Service Pack 2 (SP2) or later. 如果查询编辑器窗口连接到处于单用户模式下的实例,您将无法运行调试器。You cannot run the debugger when the Query Editor window is connected to an instance that is in single-user mode.

  • 服务器需要通过 RPC 回复客户端通信。The server needs to communicate back to the client via RPC. 运行 SQL Server 服务的帐户应具有对客户端的身份验证权限The account under which SQL Server service is running should have authenticate permissions to the client

另请参阅See Also

Transact-SQL 调试器 Transact-SQL Debugger
运行 Transact-SQL 调试器 Run the Transact-SQL Debugger
逐句通过 Transact-SQL 代码 Step Through Transact-SQL Code
Transact-SQL 调试器信息 Transact-SQL Debugger Information
数据库引擎查询编辑器 (SQL Server Management Studio)Database Engine Query Editor (SQL Server Management Studio)