5

I had a question regarding the different ways to pull up the servername when trying to access a database located on your server.

What is the difference between .\, (local), localhost, and yourcomputername? I can use all of them as the server name when I log into SQL Server.

Can I use them interchangeably or only in specific scenarios? Is there a limitation on when I can use one vs the other?

I am confused about how windows resolves all of these to the same value. Would these still work when say you are using them on the same network but across different computers (i.e. trying to access a server located on a different machine)?

0

I would say there isn't really a difference in functionality when accessing a SQL server. It's a matter of personal preference.

(local) - I don't like it because it is SQL Server specific and has special characters.

localhost - is fine if you always want to connect to the local instance of SQL-Server and when using it in a script want to make it portable between many servers.

yourcomputername - works okay interactively, but when using in scripts it will connect to the same specific server when run on another server not the local machine. This may be what you want to do, but it may not be.

.\ - I never knew this existed, I personally always use . which is the same as localhost but much shorter and works in other Windows networking scenarios as well.

1

"localhost" will not work when you'll try to access SQL server from another computer because it pointing to 127.0.0.1. "yourcomputername" should work if both computers (client and server) located in one workgroup/domain.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.