Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 4 down vote accepted

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)

share|improve this answer
    
The server name, localhost, is correct. It is the named instance name I need to create an alias for. –  Svish Aug 31 '09 at 12:18
    
Then you should use localhost\instancename as the server name. –  Massimo Aug 31 '09 at 12:20
    
what about the alias name? Should I use localhost\developer_2005 as server name and localhost\foobar as alias? Will that work? –  Svish Aug 31 '09 at 12:21
    
I checked better... looks like you actually can do that. At least in SQL server 2008 (don't know if it will work in 2005). –  Massimo Aug 31 '09 at 12:26
    
I edited my answer, try that. –  Massimo Aug 31 '09 at 12:28

You are right, what you need to do is defining a new alias in the Native Client configuration.

  • Alias name: the alias you want to create
  • Server name: the actual server name
  • Protocol: TCP/IP
  • Port: the default one (1433)

Try this:

  • Alias name: localhost\foobar
  • Server name: localhost\developer_2005
  • Protocol: TCP/IP
  • Port: 1433
share|improve this answer
    
And that is where I am. But what do I put in those fields? I don't quite get it... –  Svish Aug 31 '09 at 12:07
    
The connection string in the config file is Data Source=localhost\foobar;Initial Catalog=barfoo;Integrated Security=True with provider name System.Data.SqlClient. For it to connect correctly I must change localhost\foobar to localhost\developer_2005. How can I create an alias so that I don't have to do that? –  Svish Aug 31 '09 at 12:10
    
This can't be done; your connection string is looking for a named instance called foobar, aliases can only be used as top-level names, not as they were named instances themselves. –  Massimo Aug 31 '09 at 12:13
    
So there is no way of solving this, other than changing the connection string in the application? –  Svish Aug 31 '09 at 12:23
    
I checked better... looks like you actually can do that. At least in SQL server 2008 (don't know if it will work in 2005). –  Massimo Aug 31 '09 at 12:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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