snappymcsnap
snappymcsnap

Reputation: 2103

IP versus localhost for SQL Server connection string

Say I have SQL Server installed on a server with an IP of 10.1.2.3. If I have a process running on that server that wishes to connect to the db it can use either:

The third option will incur slightly more overhead because it needs to lookup DNS each time correct? But what of the other two options? For all intents and purposes are they identical?

Obviously IPs can change, but localhost is always localhost so that is a benefit for that option, but on the other hand IP can be used from any machine within the network, localhost only on the server itself so that's a benefit for using IP. But I'm solely concerned with speed/performance/reliability/overhead, etc

Upvotes: 1

Views: 3514

Answers (1)

John
John

Reputation: 727

For speed, your best bet is an IP, since it avoid a name lookup. There may be a reverse lookup on the server side of the connection, though. When using 'localhost', you are (likely) actually going to 127.0.0.1, not the external IP (or you should be, anyway, and if you're not something's not right). The advantage there is that you can change the external IP of the machine without having to change your connection string and things should still work.

Upvotes: 2

Related Questions