(Microsoft .NET,Microsoft SQL Server,Database)
by Jason Skowronek
If you are unfortunate enough to have to support applications running on legacy SQL Server 2000 databases like me, you are probably aware of the limitation of Visual Studio 2010 and Entity Framework 4.0 for SQL Server 2000.
There are plenty of articles out there on work-arounds. I find this one the most direct and feasible. Granted, I have not looked into possible version issue that may result in doing it this way, but for the various applications on which I have worked, it is sufficiently elegant and functional.
This a work-around. Let me repeat, this is a work-around!.
Here are the steps to add a new Entity Framework 4 entity context to a Visual Studio 2010 project:
- Download the base entity data model for SQL Server 2000 file and save it to the project folder to which you wish to add the SQL 2000 entity context. Do NOT add it to your project yet.
- Rename the EDMX file to the name of the data context (e.g. MyDataModel.edmx).
- Open the EDMX file in a text editor.
- Find/replace all references to %DB_NAME% with your own value (e.g. SomeDatabaseName).
- Add this new connection string section to your App or Web.config and find/replace with your own values:
<add name="%DB_NAME%Entities" connectionString="metadata=res://*/%DB_NAME%.csdl|res://*/%DB_NAME%.ssdl|res://*/%DB_NAME%.msl;provider=System.Data.SqlClient;provider connection string="Data Source=%DB_HOST_NAME%;Initial Catalog=%DB_NAME%;Persist Security Info=True;User ID=%DB_USER%;Password=%DB_USER_PWD%;MultipleActiveResultSets=False"" providerName="System.Data.EntityClient" />
Please note: the connection string name MUST MATCH the EntityContainer section name you specified in the EDMX file.
- After the .edmx and web.config files configured, add them to the project and verify the new entity data source appears after refreshing the Data Source manager window.
- If the new entity data source appears, open the .edmx file in design view and refresh the design model.