Ryan Adams Blog

SQL, Active Directory, Scripting

Below is a link to a white paper I wrote on Central Management Server.  This white paper is an excellent guide for those who have never used it before.  It walks you through how to use CMS from beginning to end.  Here is what you can expect to learn:

  • Where to find CMS in management studio
  • How to enable it
  • How to configure security
  • How to add connection objects
  • How to query multiple servers simultaneously
  • How to export local server connections and import them into CMS


Central Management Server White Paper

Below is a link to a white paper I wrote on Policy Based Management.  It serves as a guide to not only explain the technology but also walk you through setting it up and designing some policies.  You can expect to learn the following:

  • How to enable PBM
  • How to create a policy
  • The different ways to evaluate a policy
  • Where to find and import Microsoft best practice policies
  • How to setup alerts to be notified of policy violations
  • A list of common use cases


Policy Based Management White Paper



This post has been sitting in the draft folder for way too long, March of last year to be precise.  So although this is no longer new information, it has not been talked about all that much.  I’m talking about the new feature in SQL Server 2012 that allows you to put TempDB on local storage in a failover cluster.  That’s right.  You no longer have to house TempDB on your SAN, and why should you?

TempDB gets destroyed and re-created with each restart of the SQL Server Service so there is no need to have that happen on shared storage.  When we fail over from one node to another we don’t need the data in TempDB to still be sitting there.  So you can stop yelling at your SAN admin to “Give me more power!”  He doesn’t like you calling him Scotty anyway.

Scotty Power

What’s so great about putting TempDB on local storage?  One acronym..SSDs.  Now we can put TempDB on local storage that is fast like SSDs or even a RAID 10 that very well may be faster than your corporate SAN.  Of course this might not even be a concern for you if your application is not a heavy user of TempDB, but if you have something that’s a big hitter for TempDB this can yield some significant gains in IO.

Let me also say that this is not a get out jail free card or a cure if you are experiencing contention in TempDB.  We’re good DBAs and we’ll make sure everything is tuned and configured properly before we go throw hardware at problems, right?  That means we need to discover if we are even experiencing TempDB contention and if we are there are some other configurations we need to look at first.  For instance, multiple TempDB data files that are equally sized.  That’s a whole other post or 2, but Robert Davis (Twitter|Blog) has done a much better job in his white paper than I ever could.  Here’s a link:


I ran across an issue that I haven’t seen since SQL 2000 and had almost forgotten about.  Let’s do a quick review of ports in SQL Server.  A default instance of SQL Server uses port 1433.  That’s just the default and you can change it to whatever you want.  Bear in mind that if you change it you’ll have to define that port in your connection strings or enable the SQL Browser Service.

Speaking of the SQL Browser Service, you’ll need that for a named instance of SQL Server for the exact same reason.  A named instance of SQL Server uses a dynamic port that can change with every restart of the SQL Server service.  Take a look at the following screen shot of a named instance.

Ports in Configuration Manager

We are interested in the very last section which is the “IPAll” section.  You can see that the “TCP Dynamic Ports” is set for 49402.  That is what SQL Server has dynamically chosen for its port number.  For a normal named instance we’ll see a port there, but the “TCP Port” setting would be blank.  A default instance would be the other way around with a “TCP Port” defined but the “TCP Dynamic ports” being blank.

So what happens when you have a named instance using dynamic ports and you define a static port?  Well the title of post already gave it away, but whatever you put into the “TCP Port” setting will override anything dynamic.  I personally think it would make more sense to only be able to define one of the settings at a time.  Maybe MS will change that one day where one of them is grayed out until the value is removed from the other setting.

I’ve had several instances over the last few months where I had to reinstall the SQL Server Performance Counters.  It sounds odd to have them magically disappear, but I’ve found a 3rd party monitoring product to be the culprit.

First we need to unload the counters just to make sure everything is removed and we are starting from a clean slate.  It’s better to be safe than sorry.  Open a command prompt as an Administrator and choose one of the following:

Default Instance


Named Instance

unlodctr MSSQL$MyInstanceName

Now we need to re-load the counters.  They are stored in an INI file.  The file is located in the binn directory of the installation folder.  You can get the name of the file from the following registry key:

Default Instance


Named Instance


Now that we have the file name we just need to run the load counter command from an elevated command prompt.  Here is what the command would look like for a default instance of SQL Server 2012.

lodctr “C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\BINN\perf-MSSQLSERVERsqlctr.ini”

Hopefully this helps if it ever happens to you.

A fellow community member sent me an email saying he was having trouble authenticating with Kerberos.  Here is the error he was receiving:

SSPI handshake failed with error code 0x8009030c, state 14 while establishing a connection with integrated security; the connection has been closed. Reason: AcceptSecurityContext failed. The Windows error code indicates the cause of failure.  [CLIENT: <named pipe>].

You’ll notice that he was using Named Pipes and a lot of folks might think that is the reason for the error and that SQL Server doesn’t support Kerberos over Named Pipes.  However, that’s not the case as it is version dependent.  Kerberos over Named Pipes started being supported in SQL Server 2008 and this person was running SQL Server 2008 R2.  In this instance, that was not the issue.

I walked him through some troubleshooting scenarios to narrow down the cause.  I had him verify his SPNs to make sure they were correct, were located on the correct object in Active Directory, and he had SPNs for both the FQDN and NetBIOS names.  That all checked out so I had him verify that port 88 (Kerberos) was open between the client and server.  That also checked out fine.  I asked him this one last thing:

Also, make sure you are using Windows authentication since Kerberos does not work with SQL authentication.  If you are using Windows authentication then make sure the client and server are in the same domain or a trusted domain.

That last sentence was the ticket.  He replied that his client and server were in different domains that were NOT trusted.  Unfortunately for him, there is nothing he can do short of moving the servers into the same domain or setting up a trust between them.  That’s a core concept for how Kerberos works.  Clients and servers MUST be in the same domain or a trusted domain.

Have you ever had an error when using a SQL Server Proxy Account?  I ran across a misleading error.  Let me qualify that a little.  It wasn’t misleading in the sense of it saying one thing and meaning another.  It was misleading because it’s one of those errors you see for multiple things and I happen to see this one fairly often.  Let’s look at the error first…

Unable to start execution of step1 (reason: Error authenticating proxy SERVER1\Administrator. System error: Logon failure: unknown user name or bad password.).  The step failed.

You can see from the error that it came from a SQLAgent job.  You can also see that the job step was using a proxy account.  The last part about “unknown user name or bad password” is the part I see most often in errors.  Before you read on to the next paragraph, what’s the first thing that comes to mind as to the cause of this error?  No seriously…stop reading…what’s your first instinct?

Did you guess that it was a bad password?  You didn’t stop reading and think did you?  That would be way too obvious and easy!  My guess?  A Kerberos double hop issue.  That did not turn out to be the case.  It’s not the most common error message for a Kerb issue as you’re more likely to see an “Anonymous User” or “SSPI Context” error, but it’s not uncommon.  So what’s the issue?

The issue turned out to be someone configuring the SQLAgent service account to use a UPN or User Principal Name.  As a DBA you may be wondering what that is.  My former life was Active Directory and the simple explanation is that it’s an account name in the format “User@Domain.com”.  All you really need to know is that SQL Server does NOT support the use of UPN names.

I want to point out two things here.  The first is the user name you see in the error message.  “Server1\Administrator” is called a SAM account name.  If it had been in a UPN format the issue would have been very obvious.  However, that account is the credential that the proxy account is using.  In fact the job should have executed under the security context of that account as opposed to the account the SQLAgent service account was running under.  Since the SQLAgent was set to run using a UPN name we failed before we ever got that far.  So  how did I figure out the issue?  You’ll recall that I said I thought it was a Kerberos error, so I went to look at the SQL Server Service account so I could check the SPNs and that’s when I saw the bad account name.

The second thing I want to point out is that SQL Server Configuration Manager will NOT allow you to use a UPN.  That means the account was mostly likely set using Services.msc.  This is just another example of why you should ALWAYS use SQL Server Configuration Manager to make account changes to your SQL services.

I presented for the PASS DBA Virtual Chapter several weeks ago and talked about different ways that Active Directory can affect your SQL Server.  We only had an hour so I had to scale the content back and because of that I had a ton of questions.  I answered what we had time for on the web cast and now I’ll answer the ones I couldn’t get to in this blog post.

Q.   When we get to the Kerberos part, I’d love to find out how to resolve this error:  The SQL Network Interface library could not deregister the Service Principal Name (SPN) for the SQL Server service. Error: 0x6d3, state: 4. Administrator should deregister this SPN manually to avoid client authentication errors.

A.   Every time SQL Server starts up it attempts to register its SPNs and every time it stops SQL Server tries to unregister its SPNs.  If the SQL Server service runs under the Local System, Local Service, or Network Service accounts the SPN goes on the computer object in AD and SQL will have the permissions it needs by default to register and unregister its SPNs.  The error we see in the question indicates that it cannot unregister the SPN so either SQL Server is using a domain account to run the service or someone tampered with the permissions on the computer object in AD.  When using a domain account the SPNs go on that same account and there are several ways to unregister them.   If your Active Directory is prior to Windows 2008 then you can use ADSI edit, but if you’re on a newer version then it’s built right into Active Directory Users and Computers.  The last option is to use SETSPN.EXE.  Here is the syntax to delete an SPN followed by a screen shot of where to find it in ADUC:

SETSPN.EXE -D SQLSvc/myspnfromerror useraccountname_or_computeraccountname

Edit SPN with ADUC

Edit SPN with ADUC

Q.   Where can we find the script to check nested group membership?

A.   SQL Service Account Recursive Group Membership

Q.   Where do I find the inheritance settings?

A.   This is referring to checking the security on your database files.  Remember my tip to always check down to the file level and not just stop at the folder level.  If inheritance gets removed anywhere in the chain there very well may be lingering permissions below.  You can right click and select properties on any folder or file on your machine and go to the security tab.  Click on the advanced button and then on the edit permissions button.  If you look at the screenshot below you’ll see three things that have to do with inheritance.  The first is the “apply to” column for each permission on this object.  This column tells us if that permission only applies to this particular folder and goes no further, if it applies to this folder and every folder under it, or if it applies to every file in those folders.  The second is the first check box at the bottom which says that the permissions of the folder above this one should be inherited and also applied to this folder.  The third thing we see is the last check box which says to take the permissions for this folder and apply them to every child folder and object below it.

Inheritable Permissions

Inheritable Permissions

Q.  Any advice on what is best to choose – multiple HOST (A) records vs multiple CNAME for DNS Alias?

A.  My opinion here is that it’s a pick your own poison.  They both can have their issues if not maintained properly, but I would use a CNAME record myself.  Using an alias makes more logical sense to me and you gain the ability to change the host name without affecting your users or applications.  The only down side is forgetting to re-point it if the host changes.  Multiple host records, on the other hand, just makes troubleshooting more difficult.  Real life experience is when troubleshooting you always want to look and verify forward and reverse lookups and multiple host records make reverse lookups more confusing.

Q.  How can you use a GPO to assign a unique account to the SQL Service?

A.  There are two ways to do this.  I’ll give you the short answers here and write another blog post with the long answers.  Once I write it, I’ll put a link here for you.  The first answer is to write a script and put the script in a GPO as a startup script.  Yes you could use the other script options as well (shutdown, logon, and logoff) but this is something you’ll want to set at startup. The second option is to use Group Policy Preferences and I’ll cover that in the other post.

Q.  How does SQL Server determine permissions for an Active Directory user who is in multiple groups? Is there an order it goes in?  Does it merge permissions for all the groups you are in when checking permissions?

A.  The short answer is yes it merges it and there is no particular order.  If you are using NTLM then it all gets returned in the token from the Domain Controller.  If you are using Kerberos then it all gets included in the ticket.  The domain controller will issue a TGT or Ticket Granting Ticket that contains the account SID and the SID of every group it is a member of recursively.  There are some limits here about how many SIDs can be in a TGT and how large in size it can be.  We can get really deep here, but I’ll supress my AD side and leave that for another day.

Q.  What is the difference between SQL Server running under the LocalService account as compared to a domain account?

A.  In order to answer this question we also have to look at the LocalSystem and NetworkService accounts.  The bottom line is that using a domain service account gives you control over what it can and cannot access on the server.  You don’t get that ability when using the built in accounts and are subject to what they were built to provide.  LocalSystem gives full control over the entire server (including all of AD if it’s on a Domain Controller).  That means if SQL gets comprised while running under that account it could be exploited to gain access to the entire server and AD DB.  The inverse is true if the LocalSystem gets compromised and access is gained to your databases.  LocalService and NetworkService don’t have quite the payload as they only have the equivalent privileges of the local Users group.  The difference between them is that LocalService can only access network resources that allow anonymous access where the NetworkService account authenticates to network resources using the computer object account.

Q.  Can you talk about AD/DNS replication in the context of geographically dispersed clusters?

A.  I talked about the impact with local cluster nodes, but I didn’t specifically point out anything regarding a Geo cluster.  The same principals apply here, but on a greater scale.  It boils down to replication.  When you span a large distance that impact becomes much greater.  There are a ton of dependencies like network configuration and bandwidth, replication topology, and replication configuration like Urgent Replication.  The absolute safest thing to do here is manually set your SPNs.  My experience has show that you can let SQL do it if you have urgent replication turned on, great bandwidth, an excellent replication topology, and cluster nodes that are local to each other.  I can tell you that Microsoft will suggest doing it manually even with local cluster nodes, but I also work for a company where the previously mentioned things are not a question.  However, even in my situation I would set the SPNs manually if it were a Geo cluster instead of local cluster nodes.

Q.  Do you need to restart servers to apply a GPO and if so can you tell the GPO to do it?

A.  The vast majority of GPO settings do NOT require a restart.  The server just needs to refresh the policy.  By default the computer will refresh every 90 minutes with a 30 minute random offset, which means it could happen anywhere between 90 and 120 minutes.  You can also force the machine to refresh it’s GPO settings by opening a command prompt and running “gpupdate /force”.  As with everything there are always exceptions to the rules.  Even if you force an update there are some settings that will not take place until the computer is restarted.  I have seen some instances where two reboots are required.  GPOs have hundreds of possible settings so I won’t pretend to know all the ones that require a reboot, but I can tell you that scripts that run at logon/logoff and startup/shutdown are some of them.

Q.  We set up constrained delegation for SQL Server, but would like to also extend that delegation to work with file share access.  What changes are necessary to include other services?

A.  Constrained delegation can be tricky, but you will have to define every single service that you want to allow.  The following screen shot shows where to define that on the user account.  Click the add button and add each and every service you want to allow.

Constrained Delegation

Constrained Delegation

Q.  Is there any performance degradation by having many DNS aliases for one IP address? I’m currently looking at creating separate aliases for different systems on the same SQL box. This applies to 150 servers, totaling about 500 aliases. Is this bad for DNS?

A.  From the perspective of clients resolving the names there would not be any impact.  From a support perspective this could be an administrative nightmare if the host name ever changes or gets deleted, because you have to update or delete 500 CNAME records.  From a DNS server perspective 500 alias records should not have a huge impact in of itself, but they do take up space and have to be replicated so there is a minor impact.

Q.  If a Windows login is a member of 2 (or more) Windows groups and each group has a login with a default DB, which default DB applies?

A.  This is an excellent question, because I’ve never been asked that and don’t know the answer.  I decided it was time to test this out in my lab.  What I found is that which ever group comes first when querying sys.syslogins is the default DB you will get.  I can’t script out that system view to see if there is an ordered index on one of the columns to absolutely guarantee those results every time (I suspect CreateDate, look at it and you’ll see why).  I ran profiler during a login as well and all I can see is the login event and not the system querying to figure out which DB should be its default.  So I can’t guarantee my answer here, but I believe it will come down to the login create date and which ever login was created first will be your winner.  If anyone else knows for absolute certain and can prove it one way or another I would love to hear about it.