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?
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.
精彩评论