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.
An application or an SSMS window that uses Windows authentication stops connecting to SQL Server on another machine, and the message reads "The target principal name is incorrect. Cannot generate SSPI context." This is not a wrong-password message. The client tried to authenticate with Kerberos, found a Service Principal Name (SPN) that does not belong where Windows expected it, and gave up.
Microsoft's page for this message says that the error "typically occurs when Windows authentication fails to use the Kerberos protocol to delegate client credentials and doesn't successfully fall back to NTLM authentication. In most cases, a misconfigured Service Principal Name (SPN) causes this error."
What the error means
The Security Support Provider Interface (SSPI) is the Windows layer that does authentication. Microsoft explains that the SQL Server client asks Windows to "negotiate", which means try Kerberos or NTLM. Kerberos is used when the destination server has an associated and correctly configured SPN, and NTLM otherwise. A client that connects locally on the same machine always uses NTLM.
Microsoft's explanation of why NTLM does not rescue the connection is the useful part. The client resolves the server's fully qualified DNS name and builds an SPN from it. If that SPN does not exist anywhere, SSPI switches to NTLM and the sign-in generally succeeds. If it exists but belongs to the wrong container, the client tries it, cannot use it, and the error appears. For a service running as a local system account the right container is the computer name; for any other account it is the SQL Server startup account. Microsoft adds that authentication "uses the first SPN that it finds", so each SPN must sit on exactly one account.
A typical SPN for SQL Server in Microsoft's page looks like MSSQLSvc/SQLSERVER1.northamerica.corp.mycompany.com:1433. The port number ties the SPN to one instance.
Two details in Microsoft's explanation are worth keeping in mind before you touch anything. First, the client builds the SPN from the name it resolves, not from the name you typed: "If you use integrated security, the driver tries to resolve the server's fully qualified DNS even if you pass an IP address or a host name as the name of the server." A connection by IP address therefore does not avoid the problem. Second, Microsoft says SQL Server tries to register its own SPN when the instance starts, and that this succeeds if the SQL Server service account has Read and Write rights on servicePrincipalName in Active Directory. If it does not, an Active Directory administrator has to register the SPN by hand, with Kerberos Configuration Manager or the built-in Setspn tool. An instance that runs under a service account without those rights will never have a correct SPN of its own making.
Likely causes
| Cause | What Microsoft's page says |
|---|---|
| SPN missing | KCM reports "Required SPN is missing" when the SPN for the startup account is not in Active Directory |
| Duplicate SPN | The same SPN is registered under different accounts |
| SPN on the wrong account or an incorrect SPN registered | Delete it from the wrong account and register the correct one |
| TCP not enabled | KCM reports "TCP must be enabled to use Kerberos configuration" |
| Named instance on a dynamic port | Use a static port and register that port in the SPN |
| Name resolution wrong | Kerberos needs valid DNS; aliases can also produce an unexpected SPN |
| Account problems | The startup account is locked out, or the service was not restarted after a password change; domains or forests that cannot communicate |
Prove the cause before changing anything
All of these only read.
- Check how the client resolves the server. Microsoft gives these commands, with
SQLServer1as the example name:ping sqlserver1, thenping -a <IPAddress>. The page says that when the second command "resolves to the correct fully qualified DNS of the computer that is running SQL Server, the client-side resolution is also successful." It also suggestsTest-NetConnectionorTest-Connectionfor detailed checks. - Check for client-side aliases. Microsoft says a SQL Server alias "might cause an unexpected SPN to be generated" and says to check aliases in SQL Server Configuration Manager and the SQL Server Client Network utility.
- List what is registered. Run
setspn -Qwith the SPN you expect. Microsoft's page saysSETSPN -Q spnNamelocates the SPN and its current accounts. Microsoft's Setspn page says-X"Performs a search of duplicate SPNs" and-Llists the SPNs registered for an account. - Run Microsoft Kerberos Configuration Manager (KCM) from
KerberosConfigMgr.exe. Microsoft says to connect with a domain account that has permission to connect to the SQL Server computer, leave the server name blank if running it on the server, and clear every option on the SPN tab except SQL Server. Read the Status column: Good, Required SPN is missing, TCP must be enabled, Dynamic Port or Duplicate SPN. - On a connection that works, check which method it used:
SELECT net_transport, auth_scheme FROM sys.dm_exec_connections WHERE session_id = @@SPID;.
Example (illustrative): at contoso.com.au a reporting server RPT01 fails with the SSPI message after the SQL Server service was moved to a new service account CONTOSO\svc-sql2. setspn -Q MSSQLSvc/sql01.contoso.com.au:1433 still lists the old account CONTOSO\svc-sql. The SPN sits in the wrong container, which is the case Microsoft says triggers the error.
Fix
Fix only what the proof showed. Microsoft says that KCM fixes the error "when you consistently receive these error messages, not intermittently".
Correct an SPN
Save first. List the SPNs of each account involved, so you can restore them. Setspn's -L switch lists the SPNs of an account:
setspn -L <domain>\<accountname>
Risk: The next steps change Active Directory: they add an SPN to one account or delete it from another. Clients that currently connect with the wrong SPN may fail differently while the change replicates. Deleting an SPN that another service relies on can break that service's Kerberos sign-in. Run Setspn from an elevated prompt with rights to edit the account.
Microsoft documents two routes. In KCM, select Fix on the row, read the Warning dialog box and select Yes; if your account cannot update Active Directory, use Generate or Generate All and hand the script to an Active Directory administrator. Without KCM, the Setspn page gives these forms:
setspn -S MSSQLSvc/<hostname>.<domain>:<port> <domain>\<accountname>
setspn -D MSSQLSvc/<hostname>.<domain>:<port> <domain>\<wrong-accountname>
Microsoft recommends -S over -A because -S "verifies that there are no duplicate SPNs". Run the -D command only after setspn -Q has shown which account holds the SPN, and only for the wrong one.
To undo it, work in this order, using the listing you saved to see which SPN was added and which was deleted. First delete each SPN you added, with setspn -D <spn> <domain>\<accountname>. Only then re-add each SPN you deleted to the account that held it: setspn -S <spn> <domain>\<accountname>. Setspn's -S verifies that no duplicates exist, so it refuses to re-add an SPN while the one you added is still registered.
Use a static port for a named instance
Microsoft says that where Kerberos is needed, a named instance should use a static port, and that the same port goes into the SPN.
Save first. In SQL Server Configuration Manager, open Protocols for the instance, then TCP/IP, then the IP Addresses tab, and write down the current TCP Dynamic Ports and TCP Port values for IPAll (or for each enabled address if Listen All is No).
Disruptive step: The next steps change the instance's listening port and restart the SQL Server service. Every connection drops and every application using the old port fails until it is changed. Do this in a maintenance window.
- On the IP Addresses tab, delete the value in TCP Dynamic Ports and type the chosen port in TCP Port. Select OK.
- Under SQL Server Services, right-click SQL Server (the instance) and select Restart.
To undo it: put the recorded values back, then restart the service again.
Accounts and domains
Microsoft's page asks you to make sure you can sign in to Windows with the same domain account and password as the SQL Server service startup account. It names two situations that produce the SSPI error: the domain account is locked out, and the SQL Server service was not restarted after a password change. If your sign-in domain differs from the server's domain, check the trust relationship between the domains. Those checks change nothing; if one fails, the repair belongs to whoever owns the account or the trust, and it is recorded and reversed under that team's own change process.
Confirm the fix
- Connect from the failing client with Windows authentication.
- Run the
sys.dm_exec_connectionsquery from the checks above. Microsoft's page gives it for determining the authentication method of a connection, and itsauth_schemecolumn carries the answer. - Rerun KCM. Microsoft says to ensure that no other problems are reported.
What to watch afterwards
- The startup account. Microsoft says SQL Server registers its own SPN when the service account has Read and Write servicePrincipalName rights, and otherwise an administrator registers it. A changed service account needs the SPNs checked again.
- Password changes. Microsoft lists "You didn't restart the SQL Server service after the password change" as a cause.
- Linked servers. If a linked server uses the Impersonate option, Microsoft says the startup account needs the "Account is trusted for Delegation" right in Active Directory.
Read next
Related articles you may want next.
- TroubleshootingSQL Kerberos After Migration: Check SPNs and NTLM UseTrace client names, SQL service identities and SPNs to explain failed Kerberos authentication after migration without weakening authentication.Read article
- TroubleshootingKRB_AP_ERR_MODIFIED: duplicate SPNs and the wrong account behind a nameUsers get password prompts or access denied on a web, file or app service, and the System log shows Kerberos event 4 KRB_AP_ERR_MODIFIED. Find which account holds the service name, remove duplicates with setspn, and confirm Kerberos works.Read article
- TroubleshootingSQL Server error 18452 'Login failed. The login is from an untrusted domain and cannot be used with Integrated authentication'Error 18452 'The login is from an untrusted domain': tell a trust problem from the loopback check, a listener on the primary node or a wrong login type.Read article
Risks and limits
These steps have not been run in a lab. Microsoft's page gives no version range. Setspn changes Active Directory data that other services read. Microsoft's page lists a check that the server's domain and the connecting account are in the same forest and says that step is required for SSPI to work. These steps do not repair a cross-forest connection.
Sources
- Cannot generate SSPI context error — Microsoft Learn, page dated 2026-05-20, accessed 1 December 2026
- setspn — Microsoft Learn, page dated 2025-03-24, accessed 1 December 2026
- Register a Service Principal Name for Kerberos connections — Microsoft Learn, page dated 2026-01-27, accessed 1 December 2026
This article was originally published on .