I woke up pretty early this morning and decided to get something in my dev environment worked out that I’ve been meaning to do for a long time now. I needed to put my main Minion dev box on a domain acct for SQL. It was currently running under local system. So I switched it to use the domain acct SQLSvc. The second I restarted SQL with the new acct I got the dreaded “Cannot Generate SSPI Context”.
Here’s my fix and I’m hoping it’ll help someone in the future.
First let me say that SSPI errors can be caused by a number of things. This one turned out to be an SPN error, but it doesn’t have to be. Among other things it could be:
- DNS lookup.
- SQL Server time out of sync .
- Client time out of sync.
- Anything else that keeps Kerberos from working.
Now there are also things that can keep the SPN from being created or used. The account could not have the perms it needs to create the SPN in AD, or there could be duplicate SPNs. You can only have 1. Or you could simply have the wrong SPN. Make no mistake, this issue had caused many gray hairs in many DBAs, and I personally always sigh when it comes up because it can be fixed in 5mins or it can take 4 days and 3 MS support techs getting involved. Most of the time though, it’s more straight forward than that. I’m not going to even attempt to make this a treatise on troubleshooting every aspect of this error though. I’m just going to show you how to diagnose the SPN portion of it and quite often that’s the issue so if it doesn’t work for you it’ll at least eliminate the SPN and you can concentrate your efforts on something else.
OK, that’s enough prelim stuff, let’s get to it.
First, we need to see what SPNs we have on the box. There are 2 ways you can do that depending on what rights you have in the domain. I’m going to show you both of them so you can have a visual guide as well as a cmdline guide.
To see what SPNs you have on the box, go to the cmdline and type the following:
SETSPN –L MinionDevCon
What I’m saying here is to list (-L) the SPNs registered for the SQL box I’m interested in. In this case, MinionDevCon.
See below for the query and the results.
Also, notice that the SETSPN command isn’t case sensitive.
So above you can see that I’ve got 2 SPNs for my SQL acct on that box. Now we just have to delete one of them. However, before we fix this issue, I’ll show you another way to view the same info.
If you have access to AD, then you can also see the SPNs in the computer object properties. So go to AD and navigate to the computer object for your SQL box. Again, in my case this is MinionDevCon. Then go into the properties of that computer object. You’ll want to go to the Attribute Editor tab.
Now find servicePrincipalName and either double-click it or highlight it and hit Edit. This will show you the list of SPNs for that computer object.
Here you can see my 2 SPNs just like at the cmdline.
Deleting the extra SPN:
Deleting the bad SPN is a fairly straight forward operation. And again I’ll show you 2 ways.
At the cmdline, simply use the SETSPN cmd again and pass in the delete flag.
SETSPN -D MSSQLSvc/MinionDevCon.MIdnight.DBA:1433 MinionDevCon
So again, that’s SETSPN <SPN> <Computername>
The SPN in the cmd above should be exactly the way it was represented in the list when it was queried. Here’s the command in the query window so you can see what it looks like:
Ahhh, see there, my regular acct doesn’t have rights to do this. I wanted you to see what happens when you don’t have rights. You will quite often need to get your AD guys to do this for you. So if you just prepare the cmd and send it to them they’ll be able to make it happen. Here’s what it looks like when I log in under my domain admin acct.
And again, that cmd is simple. Call SETSPN with the -D flag, which tells it to delete. Then the exact name of the SPN followed by the name of the server.
Now let’s do the same thing in AD. So you’re still in your computer object properties like above. Simply highlight the SPN you want to drop and then click the Remove button. It’ll put it in the text box above, but just click OK and it’ll be gone.
Ok, that’s it. I didn’t have to restart my SQL service, but I’ve heard of people who have.
Now, this was just a quick tutorial on how to manage SPNs. This hole can go pretty deep. Here’s a decent link on MSDN for troubleshooting SPNs. I don’t think I like their troubleshooting because they don’t really do a good job of showing you the commands, but it’s a good explanation of the problem, what an SPN is, etc. If I remember correctly it’ll also help you choose the right SPN.