Solved

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

Posted on 2014-04-22
3
735 Views
Last Modified: 2014-04-22
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
0
Comment
Question by:John Parker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 40016131
'localhost' does not get routed over the network.  Generally the recommendation is to use 'localhost' when you don't need remote access and of course, kill or turn off any remote access in the SQL Server configuration.  That will 'improve' security by limiting access.

If you use the FQDN, the request will go thru the network for resolution even if it is for the local machine.  Only you would know if these things are actually important.  If the traffic is low and the network is not accessible by the 'outside world', then it doesn't matter much.
0
 

Author Closing Comment

by:John Parker
ID: 40016413
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!
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40016416
You're welcome, glad to help.
0

Featured Post

Simple, centralized multimedia control

Watch and learn to see how ATEN provided an easy and effective way for three jointly-owned pubs to control the 60 televisions located across their three venues utilizing the ATEN Control System, Modular Matrix Switch and HDBaseT extenders.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We recently endured a series of broadcast storms that caused our ISP to shut us down for brief periods of time. After going through a multitude of tests, we determined that the issue was related to Intel NIC drivers on some new HP desktop computers …
Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question