SQL 2019 SPN Issues

Sam Garth 26 Reputation points Microsoft Employee
2021-07-30T15:57:09.747+00:00

Hi

I have set up a SQL Server 2019 server. When it is set up to use LocalSystem I can connect from my desktop and I have KERBEROS authentication.

If I change it to use a domain account I get the following error

119399-image.png

I checked the SPN for the account and saw the below

119458-image.png

I then removed these and when I started SQL Server it had recreated them again.

In the SQL Server Logs I see the following

119482-image.png

Can anyone tell me where I have gone wrong? The only difference between this and our other servers are that this is Windows and SQL 2019 and most of our estate is 2016.

Thanks

Sam

SQL Server | Other
{count} votes

2 answers

Sort by: Most helpful
  1. Charles Thivierge 4,171 Reputation points
    2021-07-31T03:25:31.803+00:00

    Service Principal Names has to be set on the account where the service is running.

    When you have configured your SQL Server running with Local Services, the SPN's were probably on the SQL Server Computer account in Active Directory (this is why it was working)
    If you want to configure your SQL Server service to run with a service account (user account in AD or gMSA), the SPN's has to be set on the service account.

    You can run the following command from the SQL Server
    setspn -q MSSQLSvc/[SQLServerName]:1433

    This should give you the list of the SPN's as well as the AD Account where the SPN's are currently registered (computer account / user account / gMSA).

    If you want to configure your SQL Server to run with a service account, you must first remove the SPN's that are registered on the computer account and then register the SPN's to the service account.

    Here is the steps.

    1. Remove SPN from the computer account SQL01.mydomain.local
      setspn -D MSSQLSvc/SQL01:1433 SQL01
      setspn -D MSSQLSvc/SQL01.mydomain.local:1433 SQL01
    2. Register the SPN to the service account SVC-SQL01
      setspn -S MSSQLSvc/SQL01:1433 mydomain\SVC-SQL01
      setspn -S MSSQLSvc/SQL01.mydomain.local:1433 mydomain\SVC-SQL01
    3. For testing, you may have to purge kerberos tickets from your client computer
      From your client computer, open a command prompt and execute the following command: klist purge

    When completed, your client should be able to access your SQL Server using Kerberos Authentication.

    For troubleshooting, you can also enable Kerberos logging on your client computer... This can be done using this simple command from an elevated cmd or powershell:
    reg add "HKLM\SYSTEM\CurrentControlSet\Control\Lsa\Kerberos\Parameters" /v LogLevel /T REG_DWORD /d 1 /f

    This will add Kerberos errors in the System Event Log that may help you debugging.

    To stop logging Kerberos errors, just change the value 1 to 0...
    reg add "HKLM\SYSTEM\CurrentControlSet\Control\Lsa\Kerberos\Parameters" /v LogLevel /T REG_DWORD /d 0 /f

    hth

    1 person found this answer helpful.

  2. Seeya Xi-MSFT 16,661 Reputation points
    2021-08-02T07:09:21.343+00:00

    Hi @Anonymous

    For more information, please refer to : https://blog.sqlserveronline.com/2018/01/12/sql-server-target-principal-name-incorrect-cannot-generate-sspi-context/
    Quote from this:
    To run SQL Server service you can use Local System account, local user account or a domain user account. If you are using Local System account to run your SQL Service the SPN will be automatically registered. Nevertheless, if you are using domain account to run SQL Server Service and you have domain user with basic user permissions (In our case) the computer will not be able to create its own SPN.

    In case you are using domain administrator account, you will not have any problems.
    SPN will be successfully created since domain account you are using to run SQL Server Service will have domain administrator-level credentials.

    Best regards,
    Seeya


    If the response is helpful, please click "Accept Answer" and upvote it, as this could help other community members looking for similar queries.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.