Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On the subject of SQL Server connection strings, Microsoft says:

When specifying a local instance, always use (local).

The implication is that using localhost is a bad idea. But why? Or am I reading too much into the wording?

share|improve this question
I can't think if any reason why (local) would be preferred over localhost or or .... unless it is a named instance. In fact I would almost always prefer to use the machine name or FQDN, even when local, so that regardless of where I'm running the code (or have copied it) it will still connect to the right server. Of course you could go the other way on this, if your code always runs local but you're porting it to different environments. But I see no reason to prefer (local) over any of the others, and am actually confused that the doc implies that there is... – Aaron Bertrand Oct 17 '11 at 21:15
H'mmm - I've always used . (dot) or the servername / instance name. Never had an unexplained problem. – Peter Schofield Oct 17 '11 at 21:34
up vote 8 down vote accepted

This is from memory and without reference so my recall may not be accurate.

IIRC for 2005+ "(local)", "localhost" and "." are equivalent and will use the Shared Memory protocol. Prior to 2005, "(local)" and "." would use Shared Memory whereas localhost would not necessarily do so by default. Use of machine name or FQDN could result in a DNS lookup so is not recommended for a local machine connection.

Lastly, the "(local)" term (including brackets) is a special keyword, rather than a reference to the local machine.

share|improve this answer
That all sounds about right. – mrdenny Oct 18 '11 at 5:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.