2

We are working with the Entity Framework, and most of the developers have named instances of SQL Server 2008 R2.

The connection strings that EF uses look like:

<add name="MyConnectionString"
connectionString="Data Source=MyInstance\MySource;
                  Initial Catalog=MyDatabase;
                  Integrated Security=True" 
providerName="System.Data.SqlClient" />

So the problem, for multiple developers, is that the data source is different for everyone.

Previously, I'd use an ODBC DSN to get around this problem, but according to this post that's not directly available.

Is there a way to set up the connection string so that everyone's different data source can be accessed?

Community
  • 1
  • 1
Peter K.
  • 8,028
  • 4
  • 48
  • 73
  • Why not let them keep individual config files? Or, switch to a user.config model for each person to override? – Tejs Apr 07 '11 at 14:43

1 Answers1

4

We use aliases for that in our project. Every developer should create an alias with the same name (e.g. Entitydatabase) that points to his/her named instance, so the connection string can be the same. You can create an alias in Sql Server Configuration Manager, inside the SQL native client configuration node. The best is to set it for both 32 and 64 bits (if you have a 64 bit server installed). Also make sure to enable the client protocols you want to use (e.g. TCP or named pipes) to get it work. Finally, in the connection string simply use the alias name as datasource.

  • can you elaborate on this? what is an alias in this case and how does one go about creating one? – Naraen Apr 07 '11 at 14:54
  • Thanks! That did the trick; you get the banana! The only thing is that the named instance will use TCP/IP port 1433 (the default) for connections. So in addition to enabling TCP/IP, I needed to set a non-default port for my named instance to listen on... and to set the Alias to use that port. Once all the ports (planets) aligned, it all worked. We don't use the browser service, so we had to go this extra mile. – Peter K. Apr 07 '11 at 21:28