Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

Linked server error 7303 and 7399: the OLE DB provider reported an error

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

Errors 7303 and 7399 are wrappers. Microsoft lists 7303 as Cannot initialize the data source object of OLE DB provider "%ls" for linked server "%ls". and 7399 as The OLE DB provider "%ls" for linked server "%ls" reported an error. %ls, both severity 16. The first placeholder is the provider and the second is your linked server name. Read the provider message that follows the error first, then check the login mapping, the double hop, the provider's encryption default and the timeouts.

What the error means

A linked server lets one SQL Server run distributed queries against another data source through an OLE DB provider. When the provider cannot start the connection, SQL Server raises 7303 for the failed initialisation. When the provider fails during the work, it raises 7399. Microsoft says 7399 is "a generic error message from the provider" and that "whether you receive more information depends on the OLE DB provider that you use".

Microsoft's error list gives the message text for 7303, and a separate explanation page covers 7399. A third Microsoft page, "Connectivity issues with linked servers in SQL Server authentication", prints 7303 beside a provider message that reads Login failed for user 'CONTOSO\SQLPROD01$' and names a linked server account mapping issue as the cause. Its resolution is to select "Be made with this security context" for a SQL Server login. It adds that individual account mappings in the upper part of the dialog "override the main mapping settings", and that choosing "Be made without using a security context" gives "Login Failed for user NT AUTHORITY\ANONYMOUS LOGON". The provider-specific detail for either error comes from the message in your own error output.

Other messages in the same range point to a more specific cause. Error 7416 reads Access to the remote server is denied because no login-mapping exists. Error 7410 reads Remote access is not allowed for impersonated security context. Error 7202 reads Could not find server '%.*ls' in sys.servers. Verify that the correct server name was specified. If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers. Error 7314 says the provider does not contain the table, or the user lacks permission on it.

Version scope: SQL Server on Windows. The provider named SQLNCLI maps to Microsoft OLE DB Driver for SQL Server (MSOLEDBSQL) from SQL Server 2019 by default, and SQL Server Native Client is not shipped with SQL Server 2022 and later.

Likely causes

Cause What you see How to confirm
The login is not mapped, or the mapped remote login is wrong A login failure inside the 7399 text, or error 7416; or 7303 with Login failed for user in the provider message, as on Microsoft's account-mapping page Linked server login mappings, and the login list on the remote side
A double hop without delegation Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON' for Windows users on a remote client, while the same query works on the SQL Server itself The first hop's auth_scheme, and delegation on the SQL Server service account
The provider's defaults changed after an upgrade Failure appears after a driver or SQL Server upgrade, with an encryption or certificate message Provider name in sys.servers and the text after the 7399 message
A timeout 7399 with Timeout expired inside Query duration against the timeout settings
The security option "Be made without using a security context" is selected Login Failed for user NT AUTHORITY\ANONYMOUS LOGON (Microsoft's account-mapping page) The security page of the linked server's properties

Prove the cause before changing anything

These steps only read, except the trace flag, which is session-scoped.

1. Get the provider message for 7399. Microsoft's 7399 page says that in some cases trace flag 7300 produces a more detailed error from the provider, and that the result depends on the OLE DB provider. Microsoft documents the flag on that page for 7399 only; for 7303, read the provider message in the error output. Run it in the same session as the failing query, before the query:

DBCC TRACEON (7300, 3604);

Risk: the flag needs sysadmin, and without the -1 argument Microsoft documents it as a session flag, visible only to that connection. Turn it off afterwards with DBCC TRACEOFF (7300, 3604);.

2. List the linked server and its provider.

SELECT name, provider, data_source, is_linked, is_data_access_enabled, is_rpc_out_enabled
FROM sys.servers
WHERE is_linked = 1;

3. List the login mappings. This is adapted from example E ("Check linked logins") on Microsoft's sp_addlinkedsrvlogin page. That example has a typo (sys server_principals) and uses an INNER JOIN, which drops the default mapping because its local_principal_id is 0 ("wildcard or public" on the sys.linked_logins page). This version uses a LEFT JOIN so the default mapping still shows, with a NULL principal_name:

SELECT s.name AS server_name, ll.remote_name, sp.name AS principal_name
FROM sys.servers AS s
INNER JOIN sys.linked_logins AS ll ON s.server_id = ll.server_id
LEFT JOIN sys.server_principals AS sp ON ll.local_principal_id = sp.principal_id
WHERE s.is_linked = 1;

Microsoft documents that a default mapping is created by sp_addlinkedserver, that it uses the user's own credentials, and that explicit mappings for individual logins take precedence over it.

4. Test the connection in the right context. EXECUTE sp_testlinkedserver N'sql02'; raises an exception with the reason on failure, and no permissions are checked beyond the caller needing a login mapping. In SSMS, Test Connection tests "in your current security context". A pass there does not prove the application's own context, particularly across two hops.

5. Check the first hop. Microsoft's gMSA Kerberos page runs klist purge on the client before the retest.

Risk: klist purge empties the Kerberos ticket cache of that session on the client, so the next connection asks for new tickets. There is nothing to restore. Then, from a remote, Windows-authenticated session, run:

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

Microsoft's expected result for a healthy first hop is KERBEROS. A different scheme means the second hop cannot use the user's identity. Missing, duplicate or misplaced SPNs are a separate subject.

Reading the results: a login message in the provider text points to the mapping. ANONYMOUS LOGON has more than one documented source. Microsoft's account-mapping page ties it to the "Be made without using a security context" option, and its 18456 page lists a double hop with SPN problems, NTLM loopback protection, duplicate SPNs, a Sensitive account and a target that is not on the constrained delegation list. Check the mapping option first, since it is read from the linked server's properties. If the mapping is a security context and the local test succeeds, the double hop is the next check. A message about encryption, certificates or a missing driver points to the provider. Timeout expired points to the timeouts.

Fix

Mapping. Use the mapping that matches how people connect. Microsoft's Create Linked Servers page says: "In a domain environment where users are connecting by using their domain logins, selecting Be made using the login's current security context is often the best choice. When users connect to the original SQL Server by using a SQL Server login, the best choice is often to select By using this security context". Its account-mapping page, for a SQL Server login, says to select "Be made with this security context".

EXECUTE master.dbo.sp_addlinkedsrvlogin
    @rmtsrvname = N'sql02',
    @useself = N'False',
    @locallogin = N'<local_login_name>',
    @rmtuser = N'<remote_login>',
    @rmtpassword = N'<remote_password>';

Disruptive step: this adds or replaces a mapping. Microsoft's caution on the matching example reads: "This example doesn't use Windows Authentication. Passwords will be transmitted unencrypted. Passwords might be visible in data source definitions and scripts that are saved to disk, in backups, and in log files. Never use an administrator password in this kind of connection." A default mapping created with "Be made using this security context" lets any user on the instance reach the remote server with that login, so grant that remote login the minimum permissions. To back out, sp_droplinkedsrvlogin 'sql02', '<local_login_name>' removes the explicit mapping, and the default mapping applies again.

Double hop. Microsoft states that delegation is not needed for a single hop and is required for multiple hops. With the "current security context" option, a query from a client to sql01 to sql02 is two hops. The delegation has to be set on the account that runs SQL Server. The Microsoft list of causes for ANONYMOUS LOGON includes SPN problems, an account marked Sensitive in Active Directory, a target SPN that is not on the constrained delegation list, and, for intermittent failures after long sessions, an expired ticket that the middle tier cannot renew.

Disruptive step: delegation changes are made in Active Directory by an administrator and change what the service account may do on users' behalf. Record the current settings first, and restore them to back out. There is no change on the SQL Server side that substitutes for them, except switching to an explicit SQL login mapping.

Provider defaults. Microsoft's release notes for OLE DB Driver 19.0.0 mark a breaking change: "Encrypted connections are enabled by default." They also say the server certificate is now validated when client-side encryption is off but the server requires encryption. The preferred fix is a certificate the client trusts on the remote server. The notes also name the way back: opt in to non-encrypted connections and trust the server certificate. They do not show how to apply these options to a linked server; the Create Linked Servers page lists a provider string field for that.

Risk: trusting the server certificate and turning encryption off removes protection of data and credentials between the two servers. Use it only as a short-lived step, and to back out restore the original provider string.

Timeouts. Microsoft's 7399 page says the remote query timeout default is 600 seconds and describes setting it to 0 instance-wide. Prefer a limit on the one linked server. Microsoft documents query timeout and connect timeout options in sp_serveroption, where 0 means the sp_configure default, and the remote login timeout default is 10 seconds.

The 7399 page separates two cases. A "Timeout expired" message that names IDBInitialize::Initialize means the connection to the remote server took longer than the remote login timeout (Microsoft's example sets it to 30 seconds). One that names ICommandText::Execute means the query ran longer than the remote query timeout. For the query case:

EXECUTE sp_serveroption N'sql02', 'query timeout', N'1200';

Risk: a longer limit lets a runaway query hold resources on both servers for longer. To back out, restore the previous value (0 if it was the default, which means the sp_configure default applies).

For the Initialize case, connect timeout is the per-linked-server option:

EXECUTE sp_serveroption N'sql02', 'connect timeout', N'30';

Risk: a longer connect timeout makes every query to an unreachable remote server wait longer before it fails. To back out, restore the previous value (0 if it was the default).

Confirm the fix

Run the original query as the real application account, not as an administrator. Run sp_testlinkedserver and the four-part test from Microsoft's page, for example SELECT name FROM [sql02].master.sys.databases;. Then turn trace flag 7300 off.

Example (illustrative): a report on workstation ws07 calls sql01, which reads a table on sql02 through a linked server set to use the login's current security context. The report fails with 7399 and NT AUTHORITY\ANONYMOUS LOGON, although the same query takes 4 seconds when run on sql01 itself. The first hop shows KERBEROS. There are two hops (ws07 to sql01, then sql01 to sql02), and the service account on sql01 has no delegation to sql02. After the Active Directory administrator adds constrained delegation to the sql02 service, the report works.

What to watch afterwards

  • After every SQL Server or driver upgrade, rerun the linked server tests as a real application account.
  • Keep a list of linked servers with their provider, mapping type and owner.
  • Re-check delegation after any change of service account.

Risks and limits

These commands have not been run or lab-tested. Microsoft's pages do not describe the provider-specific causes of 7303 or 7399 for every provider, so a provider that reports nothing may need its own documentation. Trace flag 7300 is documented for 7399 only, and Microsoft says whether it gives more detail depends on the provider. Changes to mappings, timeouts and delegation alter access for every user of the linked server.

Sources