Take the 2-minute tour ×
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. It's 100% free, no registration required.

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
1  
I can't think if any reason why (local) would be preferred over localhost or 127.0.0.1 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

1 Answer 1

up vote 7 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

 
discard

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.