Sql-server – How to create an alias for a named SQL Server instance

aliaslocalhostsql server

On my developer computer I have an SQL Server instance named developer_2005. In the resource setting files of a C# application we are creating, the instance name is set to foobar (not really, but just as an example). So when I run the application (in debug or realease) it tries to connect to an SQL Server on localhost, named foobar.

I am wondering if it is possible to create an alias or something like that, so that the application actually finds an SQL Server on localhost named foobar, but it is actually connecting to the instance named developer_2005.

The connection string in the config file of the application is Data Source=localhost\foobar;Initial Catalog=barfoo;Integrated Security=True with provider name System.Data.SqlClient. If I change localhost\foobar to localhost\developer_2005 then the application can connect like it should. How can I create an alias so that I won't have to change the string in the file?

I tried, in SQL Server Management Studio, to create a Server Registration with registered server name "localhost\developer", but this didn't seem to do any good. Not even sure what that really did… But then I discovered SQL Server Configuration Manager\SQL Native Client COnfiguration\Aliases. And I kind of assume this is where the solution lies. But I can't quite figure out how to add a new one… When creating a new one, I have to provide Alias Name, Port No, Protocol and Server, and I don't really have a clue what to put in either of them.

Best Answer

Alias name: foobar (the name you would like to use)

Server name: the actual name of your computer or the IP address (not localhost or 127.0.0.1)

Protocol: TCP/IP

Port: the default one (1433)

Make sure TCP/IP protocoll is enabled (disabled by default)

Change your connection string to use your new alias (Data Source=foobar)