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?
|
On the subject of SQL Server connection strings, Microsoft says:
The implication is that using |
|||
|
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. |
||||
|
|
(local)would be preferred overlocalhostor127.0.0.1or.... 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