Link to home
Start Free TrialLog in
Avatar of John Parker
John ParkerFlag for United States of America

asked on

Best Practice - SQL Server Connection String - Localhost versus Network Path

Experts,

I have a "Best Practice" question for you.  I am developing an ASP.NET website with C# code behind that connects to my SQL Server 2008 database.  Both the SQL Server and the web site are hosted on the same server.

My question is this: what is the better practice when constructing the Database Connection String in the ASP.NET site?  Should I use "localhost" when referring to the SQL Server, or should I use the fully qualified network path?

Is there any difference in the way the physical server handles the data request from the ASP.NET code if it's going to localhost versus the network path?  If I use the network path, is the server smart enough to know that the request is directed to itself, and not route the request out the TCP/IP port, to the switch, and back to the TCP/IP port?  If I use localhost, does the request get routed directly within the server without traveling to itself over the network?  The advantage for me when using the fully qualified network path is that the code works on both the server, and on my development PC.  However, I don't want needless traffic going out over the network if it doesn't have to on the production server.

Thoughts?

Thanks!

John
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of John Parker

ASKER

Awesome!  Exactly what I was looking for.  Sounds like it will be cleaner, safer, and better on my network to update my connection strings to use local host when deploying the site to the server.  Thanks!
You're welcome, glad to help.