最近在配置linked server出现了double hop相关的错误。以下是引用一位网友的blog,做个简单的记录,方便以后查阅。
link: http://blogs.msdn.com/b/sql_protocols/archive/2006/08/10/694657.aspx
SQL Server 2005: “Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'”.
SQL Server 2000: "Login failed for user "(null)". Reason: Not associated with a trusted SQL Server connection".
The errors listed above is very typical when deploy linked server with delegation. They actually are thrown by the linked server and pass by middle server to the client application. In this post, I will discuss how to properly configure SQL instances and Windows environment in most common scenario and try to make configuration steps as explicit as possible.
By using delegation in distributed query, such as linked server query, the SQL instance obtains impersonated token of the user logon credential to gain access to resources of another SQL instance, the linked server. In delegation setting, the client connection and linked server object are configured to use integrated authentication in SQL Server’s term as opposed to SQL login. Some time integrated authentication also referred as trusted connection or Windows authentication. Linked server login can also use SQL login, but it is not discussed here.
To simplify the discussion, let’s assume two SQL Server instances are installed on machine A and B respectively. Also, let’s assume A is the middle server that has a linked server object configured which points to a SQL instance on machine B. If the client is on machine C different from A, we call it double-hop setting; if the client is collocated with middle server machine A, we call it single-hop setting. In single-hop setting, it is relatively straightforward to configure linked server to work. Believe or not, double-hop setting requires more careful configurations as you will see. This is because in single-hop setting, windows NTLM authentication, which is available in most common setting if all machines are windows, is sufficient for delegation; while in double-hop setting, Kerberos authentication is mandate for flowing user’s credential through machine boundaries from the client to the linked server. It requires windows domain, correct DNS name resolution, proper account setting in both Active Directory and SQL Server. To make sure Kerberos delegation [1] is correct becomes vital to operate distributed query with delegation. The authentication scheme required by delegation in different setting is illustrated by the following table.
Authentication scheme |
C to A |
A to B |
Single hop |
NTLM or Kerberos (C is on the same box as A) |
NTLM or Kerberos |
Double hops |
Kerberos |
Kerberos |
[Create Linked Server Object on Middle Server]
Before getting into details on how to configure other components, since I am talking about delegation in the context of SQL Server distributed query, let’s first give an example on how to configure a linked server object on A and set up its login to use delegation. To do so, you need the following two steps.
(1) Use sp_addlinkedserver to create a linked server object and name it “LinkedServer” which points to the SQL instance on machine B, SQLB.
“EXEC sp_addlinkedserver @server=’LinkedServer’,
@srvproduct=''”,
@provider='SQLNCLI',
@datasrc=’SQLB’,--the data source
@provstr="Integrated Security=SSPI; "
“
To verify if the command is executed correctly, run query
“select * from sys.servers where name='LinkedServer'”;
(2) Use sp_addlinkedsrvlogin to configure login to use self-mapping as following
“exec sp_addlinkedsrvlogin ‘LinkedServer’, 'true'”
Step (2) makes middle server A try to use impersonated token of user to authenticate to server B. To verify that the linked server is setup for “self-mapping”, run query
“select uses_self_credential as delegation
from sys.linked_logins as L, sys.servers as S
where S.server_id=L.server_id
and S.name=N'LinkedServer'
The resulting table should show the delegation column is “1”.
[Test Linked Server Query in Single-hop Settting]
Before test-drive a link server query in single-hop setting, you need also make sure that the client user can make direct query to the SQL instances on both A and B. This means that the user account, either windows domain account or a machine account, must have permission to access both SQL instances.
(3) To verify the user domain account has permission to access both SQL instances, use your favorite client tool, for example,“osql –E –S SQLA” and “osql –E –S SQLB”. If you are failing for whatever reason, please refer to [5][6].
(4) To test linked server query, run query at SQLA,
“select * from LinkedServer.master.dbo.sysdatabases”.
[Configure and Test Double-hop Setting]
To deploy delegation based linked server in double-hop setting, the followings need to be configured correctly.
(3) Kerberos in Windows mandates Windows domain. Therefore the user account needs to be a domain account and middle server and linked server need to join a domain. All machines involved in the delegation, including client machine, middle server and linked server, must have good TCP/IP connectivity between each other and to the domain controller and Active Directory. To not complicate thing further, we assume that A, B and C are in same Windows domain D and the user account is a domain account in D.
(4) The user’s domain account must NOT select “Account is sensitive and cannot be delegated” in its Active Directory properties of domain D. Please refer to [1] on how to configure this on Active Directory machine.
(5) The service account under which the SQL instance is running must be “trusted for delegation”, configured in Active Directory. If the service is running as “NT AUTHORITY\SYSTEM” or “NT AUTHORITY\NETWORK SERVICE”, the computer must be “trusted for delegation”. Please refer to [1] on how to configure this on Active Directory Machine. You need to have domain admin privilege to do/verify so.
(6) The user domain account must have permission to access both SQL instances from C. To verify, use your favorite client tool, for example,“osql –E –S SQLA” and “osql –E –S SQLB”. If you are failing for whatever reason, please refer to [5][6].
(7) If the SQL connections are to use TCP/IP connectivity, configure and verify that SQL connections from C to A and A to B are using Kerberos authentication. Please refer to [2] on how to configure Kerberos for SQL. In a nutshell, both services on machine A and B need to have a SPN created in Active Directory for SQL service. If the service running account is not “NT AUTHORITY\SYSTEM”, you need to configure the SPN on the Active Directory Machine with domain admin privileges. To verify that every hop is using Kerberos and TCP connectivity, run query
“select net_transport, auth_scheme from sys.dm_exec_connections where session_id=@@spid”
when (a) connect to A from C (b) connect to B from A. To make Kerberos work for both hops is crucial and some time it might not be very straightforward on what goes wrong. If fail to get Kerberos to work, please (a) verify If the SPNs are configured and well-formed according to [4]; use “setspn –L acccoutname” to verify the SPN (b) verify if DNS reverse lookups of both machine A and B return well-formed FQDNs. Use “ping –a machinename” on machine A, B and C to verify DNS works as expected, i.e. returning FQDN; (c) make sure that there is no cached Kerberos ticket on machine A and C. Use “klist purge” to purge all tickets. There might be delay before Windows local security authority (LSA) requests a new ticket from Active Directory. Sometime, you need to log out and log back in again before a new Kerberos ticket can take effect. For more Kerberos troubleshooting techniques, please refer to [3].
(8) If the SQL connections are to use Named Pipe connectivity, SQL level Kerberos is not required as opposed to TCP connectivity. This is because Windows named pipe protocol can use Kerberos to authenticate logon user under the cover. You need to verify that both machine SPNs “HOST/machinename” and “HOST/ machineFQDN” is well-formed use “setspn –L machinename”.
(9) Since double-hop can have combination of Named pipe connectivity on one hop and TCP on the other, the following table is valid configuration for delegation. Run query
“select net_transport, auth_scheme from sys.dm_exec_connections where session_id=@@spid”
when (a) connect to A from C (b) connect to B from A.
{net transport, auth_scheme} |
C to A |
A to B |
1 |
NP, NTLM* |
NP, NTLM* |
2 |
TCP, Kerberos |
NP, NTLM* |
3 |
NP, NTLM* |
TCP, Kerberos |
4 |
TCP, Kerberos |
TCP, Kerberos |
* Note that even SQL shows NP is using NTLM at SQL level, Windows named pipe protocol can still use Kerberos under the cover ( the SMB/CIFS windows file system, upon which the named pipe is implemented, can use Kerberos) that allows Kerberos delegation.
After verifying the above 9 steps, finally we come to the point to run a double-hop linked query. If you still encounter issues after follow these steps, please send me the error message, your configuration, the output of the queries listed for every step and information required by [6].
In discussion above, we assume the A,B and C are in the same domain. If they are in different domains, apart from verifying 9 steps listed above, you also need to make the domains involved trust each other.
Note that setspn.exe, klist.exe referred in this post can be downloaded as part of Windows resource kit. Kerberos delegation is only supported on windows 2000 and onward.
[Reference]
[1] Troubleshooting Kerberos Delegation. http://www.microsoft.com/technet/prodtechnol/windowsserver2003/technologies/security/tkerbdel.mspx
[2] Using Kerberos with SQL Server. http://blogs.msdn.com/sql_protocols/archive/2005/10/12/479871.aspx
[3] Troubleshooting Kerberos Errors. http://www.microsoft.com/technet/prodtechnol/windowsserver2003/technologies/security/tkerberr.mspx
[4] http://support.microsoft.com/kb/889615/en-us
[5] http://support.microsoft.com/?id=840219
[6] http://blogs.msdn.com/sql_protocols/archive/2006/04/21/581035.aspx
相关推荐
"Windows Server 2008 内 SQL Server 建立 Linked Server 连接 Oracle" 在 Windows Server 2008 64 位操作系统中,使用 SQL Server 建立 Linked Server 连接 Oracle 数据库是一种常见的需求。然而,在 64 位操作...
SQL Server 2008 R2 开启数据库的远程连接及客户端配置 在 SQL Server 2008 R2 中,默认是不允许远程连接的。如果想要在本地使用 SSMS 连接远程服务器上的 SQL Server 2008,远程连接数据库。需要做两个部分的配置...
打开 SQL Server Management Studio,进入 Server Objects 列表,右键 Linked Servers,点击“New Linked Server...”在 General 界面中填写下面几项内容: * Linked server: 填写 Linked Server 名称 * Provider...
本问题涉及到SQL Server访问MySQL数据库时遇到的字符编码问题,导致中文显示为乱码。以下是对这个问题的详细分析和解决方法。 首先,问题的核心在于字符编码不匹配。SQL Server和MySQL可能使用了不同的字符集来处理...
在众多实现方式中,SQL Server通过LINKED SERVER机制以及ODBC(开放式数据库连接)技术实现了与其他数据库,尤其是与Microsoft Access数据库的连接。 #### 测试环境与软件需求 在进行SQL Server与Access数据库的...
本文将详细介绍如何通过配置Linked Server以及使用Oracle的透明网关(Oracle Gateway for Microsoft SQL Server, 简称TG4MS)来实现SQLServer2008 R2与Oracle11g R2之间的互连。 #### 2. 环境信息 - **SQLServer ...
When you add SQL2 as a linked server to SQL1, you can reference tables and views on SQL2 directly from SQL1 using the four-part naming convention (linked_server.database.schema.table). - **Remote ...
SQL Server 2000提供了“开放数据库连接”(ODBC)和“数据库链接”(Linked Server)两种方式来实现这一功能。ODBC是通过数据源管理器创建一个指向Oracle数据库的ODBC数据源,然后在SQL Server中使用SQL Server ODBC...
标题中的“linked server”指的是SQL Server中的一个特性,它允许SQL Server实例与其他数据库管理系统(DBMS)进行交互,实现跨数据库查询和数据操作。通过设置链接服务器,用户可以在同一个SQL查询中访问和操作不同...
在SQL Server中,连接服务器(Linked Server)是一种使一个SQL Server实例能够访问另一个SQL Server实例或非SQL Server数据源的技术。通过连接服务器,可以实现跨数据库、跨平台的数据查询与操作,极大地扩展了SQL ...
在IT领域,数据库之间的互操作性是至关重要的,特别是在企业级应用中,SQL Server和Oracle数据库的集成常常被需要。本文将详细介绍如何在SQL Server上安装Oracle Provider for OLE DB驱动,以便创建与Oracle数据库的...
如何把Excel 文件变成 Linked Server 的 SQL源码。 好处是你可以很轻松的用 SELECT 来拿 Excel 里的数据。 如:SELECT * FROM ExcelLinkedServer
### 数据库分布式查询Sqlserver详解 #### 一、引言 在进行软件开发的过程中,我们经常会遇到这样的场景:数据分布在不同的服务器上,而我们需要在这些不同的数据库之间进行查询、更新等操作。这种需求催生了数据库...
SQL Server是微软公司推出的一款关系型数据库管理系统,广泛应用于企业数据存储、管理和分析。这篇文档“SQLServer面试题.doc”显然包含了与SQL Server相关的面试问题,可能是为了帮助求职者准备数据库管理员(DBA)...
### SQL Server跨数据库实例取数方式详解 在SQL Server环境中,有时我们需要从不同的数据库实例中获取数据。这种需求可以通过创建链接服务器(Linked Server)来实现。本文将详细介绍如何通过SQL Server实现跨...
2. 配置SQL Server的Linked Server:在SQL Server Management Studio中,右键点击“服务器对象”->“链接服务器”,选择“新建链接服务器”对话框。在“常规”选项卡中,为链接服务器指定一个名称,如“OracleLink”...
### SQL Server DBA 名企面试问题及答案 #### 1. 磁盘柜配置与数据库物理部署 **问题背景**:给定一个磁盘柜,包含14块73G的磁盘,需要配置以支持一个200G大小(含日志文件)的数据库。 **解决方案**: - **RAID...
### SQL Server跨服务器连接的多种方法 #### 一、引言 在企业级应用中,经常需要在不同的SQL Server实例之间进行数据交换或共享。为了实现这一目标,SQL Server提供了几种跨服务器连接的方法,每种方法都有其特点和...