views:

95

answers:

2

I am working on a code base that has a number of connection strings that access a database server by a specified name.

<add name="myConnection" 
     connectionString="Data Source=DevServer;Initial Catalog='devData';Persist Security Info=True;User ID=devUser;Password=devPass;" 
     providerName="System.Data.SqlClient" />

I am in a location that does not have access to the named "DevServer" Data Source.
I have a version of the database hosted locally in "localhost".
What I would like to do is have my "localhost" database accessible via the Data Source named "DevServer".

I don't want to lose the ability to access the server via "localhost" as I have other projects that use this as a Data Source. I could alter the config files, but I would then have to ensure that I don't check them in, as that would break the configuration for others. I still want to receive any updates to the config files, so having local writeable versions is not an option.

I have tried using the SQL Server Configuration Manager to create an Alias, but I think that I did something wrong as I am still unable to connect using "DevServer".

Should SQL Server Configuration Manager be able to achieve what I am trying?
Can anyone suggest a way that I can achieve this?

I guess my question is similar to this but there has been no accepted answer and it is for SQL Express.

+5  A: 

You could update your hosts file to alias your machinename to DevServer:

127.0.0.1       localhost

# Comment this line out when back on the normal network:
127.0.0.1       DevServer
Michael Haren
This did work, but I managed to get the SSCM approaching working too. I am going to stick with the SSCM as this is the way that I was trying in the first place. Thank you for your answer.
AidenMontgomery
This approach doesn't require a reboot. Hopefully SSCM doesn't either--update us if you determine that either way! Good luck
Michael Haren
Just to confirm, SSCM doesn't need a reboot. I have tested this approach on an XP machine and a server 2003 machine. Neither required a reboot.
AidenMontgomery
Thanks for following up!
Michael Haren
+1  A: 

The SQL Server Configuration Manager allows you to use a put in an alias, under the Native Client Configuration. I think that's easier to me, but the hosts file solution should work just as well.

If you use the SSCM, be sure you back this out when you hit the main network (or edit it), or you won't be able to hit the correct server.

Steve Jones
Thank you.I was convinced that I'd done something wrong or that my approach wouldn't work.However after your reassurance I tried it again.I rebooted my machine after creating the alias and it did indeed work.A reboot is probably overkill,but it accomplished something that I missed previously.
AidenMontgomery