Guides

Linked server login failed for NT AUTHORITY\ANONYMOUS LOGON (Msg 18456 / 7399)

By Scott Coffey, Senior Database Developer. Updated 2026-11-06.

You run OPENQUERY, a four-part name, or sp_testlinkedserver against a linked server, and SQL Server returns something like this:

Msg 7399, Level 16, State 1
The OLE DB provider "MSOLEDBSQL" for linked server "LS_REMOTE" reported an error.
Authentication failed.

Msg 7303, Level 16, State 1
Cannot initialize the data source object of OLE DB provider "MSOLEDBSQL" for linked server "LS_REMOTE".

Msg 18456, Level 14, State 1
Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.

Msg 7399 and Msg 7303 are the outer OLE DB / provider failures. The inner Msg 18456 is the one that names the account: the remote SQL Server saw NT AUTHORITY\ANONYMOUS LOGON and refused the login. That is almost never the account you intended.

What causes it

The usual cause is a Windows authentication double hop. Your Windows login reaches the local SQL Server (hop 1). The linked server is mapped with @useself = TRUE, so the local instance tries to present your Windows identity to the remote instance (hop 2). Without Kerberos constrained delegation set up for that path, Windows cannot forward the ticket. The remote side receives an anonymous token and logs Msg 18456 for NT AUTHORITY\ANONYMOUS LOGON.

Other linked-server failures can also surface as Msg 7399 or 7303 without ANONYMOUS LOGON:

  • An explicit SQL login mapping with the wrong remote user or password.
  • No login mapping for the local login that is calling the linked server.
  • Provider, network, TLS, or firewall problems that never reach a login attempt.

Treat ANONYMOUS LOGON as a credential-forwarding problem first. Treat a bare 7399/7303 without that inner text as a separate connectivity or mapping problem.

If you are still building the linked server and hit Msg 15002 inside a transaction, that is a different error; see the Msg 15002 linked-server guide.

Step 1: confirm the mapping and the provider

Read the linked server definition and its login mappings. These queries are read-only:

SELECT s.name, s.provider, s.data_source,
       s.is_data_access_enabled, s.is_rpc_out_enabled,
       s.connect_timeout, s.query_timeout
FROM sys.servers AS s
WHERE s.is_linked = 1
ORDER BY s.name;
SELECT srv.name AS linked_server,
       CASE WHEN ll.local_principal_id = 0 THEN N'(all local logins)'
            ELSE sp.name END AS local_login,
       ll.uses_self_credential,
       ll.remote_name
FROM sys.linked_logins AS ll
JOIN sys.servers AS srv ON srv.server_id = ll.server_id
LEFT JOIN sys.server_principals AS sp ON sp.principal_id = ll.local_principal_id
WHERE srv.is_linked = 1
ORDER BY srv.name, local_login;

EXEC sp_helplinkedsrvlogin;

uses_self_credential = 1 with a blank remote_name is pass-through Windows auth: the double-hop case. A row with uses_self_credential = 0 and a remote_name is an explicit remote SQL login mapping. sp_helplinkedsrvlogin shows the same information in the classic procedure form.

Also note the provider. Prefer MSOLEDBSQL for SQL Server targets; SQLNCLI is deprecated.

Step 2: reproduce with sp_testlinkedserver

Isolate connectivity from your application query:

BEGIN TRY
    EXEC master.sys.sp_testlinkedserver @servername = N'LS_REMOTE';
    PRINT 'Linked server OK';
END TRY
BEGIN CATCH
    PRINT 'Linked server FAILED: ' + ERROR_MESSAGE();
    THROW;
END CATCH;

If this fails with ANONYMOUS LOGON, the mapping or Kerberos path is wrong before any remote query text matters. The SQL Rig linked-server-test.sql script and Test-LinkedServer.ps1 wrap the same call for one or all linked servers and return elapsed milliseconds.

Step 3: check whether the local connection is Kerberos

Pass-through only works when the local session can be delegated. On a domain-joined Windows host, check the current connection:

SELECT auth_scheme, net_transport, local_net_address, client_net_address
FROM sys.dm_exec_connections
WHERE session_id = @@SPID;

KERBEROS is required for constrained delegation. NTLM cannot do the second hop, so a useself mapping from an NTLM session is a common way to end up at ANONYMOUS LOGON. This check is less useful on a local SQL login session (you will see SQL), which is expected when you are using an explicit remote SQL mapping instead.

Step 4: fix it the pack way

Pick one of these, not a mix of workarounds.

(a) Prefer an explicit least-privilege remote SQL login mapped to a specific local login. This avoids the double hop entirely. The SQL Rig linked-server-add.sql pattern refuses to map every local login to one fixed remote login, and it never puts a password literal in the script:

-- Set @DryRun = 0 only after reviewing the printed plan.
-- Supply the remote password at run time (sqlcmd -v), never as a literal in source.
DECLARE @DryRun      bit     = 1;
DECLARE @LinkedName  sysname = N'LS_REMOTE';
DECLARE @DataSource  nvarchar(4000) = N'remote-host,1433';
DECLARE @LocalLogin  sysname = N'CONTOSO\svc_etl';     -- specific local login only
DECLARE @RemoteLogin sysname = N'ls_etl_reader';       -- least-privilege remote SQL login

-- linked-server-add.sql does the equivalent with MSOLEDBSQL, timeouts,
-- rpc out off by default, and THROW 50001 if @RemoteLogin is set without @LocalLogin:
--   EXEC sp_addlinkedsrvlogin
--        @rmtsrvname  = @LinkedName,
--        @useself     = N'FALSE',
--        @locallogin  = @LocalLogin,
--        @rmtuser     = @RemoteLogin,
--        @rmtpassword = @RemotePassword;

Grant that remote login only the rights the remote query needs. Do not map everyone to a remote sysadmin.

(b) If you truly need Windows pass-through, keep @useself = TRUE and configure Kerberos constrained delegation correctly: SPNs for both SQL instances, the local SQL Server service account trusted for delegation to the remote MSSQLSvc SPN, and a Kerberos (auth_scheme = KERBEROS) session on the local side. That is an Active Directory and service-account change, not a T-SQL switch.

(c) Do not "fix" it with xp_cmdshell, a second hop through cmd.exe, or by mapping all local logins to a powerful remote account. Those widen the blast radius and leave the real auth problem in place.

Step 5: prevent the next one

Create linked servers with a dry run first. linked-server-add.sql defaults @DryRun = 1, uses MSOLEDBSQL, sets connect and query timeouts, leaves RPC out off unless you need EXEC ... AT, and turns remote proc transaction promotion off. After you create the server, run linked-server-test.sql or:

./Test-LinkedServer.ps1 -ServerInstance 'SQL01' -LinkedServer 'LS_REMOTE'

Prefer OPENQUERY for remote filtering so the remote engine applies predicates; four-part names can pull large remote tables locally when the optimizer cannot push the predicate. The pack file linked-server-openquery.sql shows the safe patterns.