Home → Resources → Articles

How To Use Entity Framework 4 With Visual Studio 2010 and SQL Server 2000

(Microsoft .NET,Microsoft SQL Server,Database) by Jason Skowronek on 11/07/2011

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:

  1. 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.
  2. Rename the EDMX file to the name of the data context (e.g. MyDataModel.edmx).
  3. Open the EDMX file in a text editor.
  4. Find/replace all references to %DB_NAME% with your own value (e.g. SomeDatabaseName).
  5. Add this new connection string section to your App or Web.config and find/replace with your own values:
    <connectionStrings>
      <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=&quot;Data Source=%DB_HOST_NAME%;Initial Catalog=%DB_NAME%;Persist Security Info=True;User ID=%DB_USER%;Password=%DB_USER_PWD%;MultipleActiveResultSets=False&quot;" providerName="System.Data.EntityClient" />
    </connectionStrings>

    Please note: the connection string name MUST MATCH the EntityContainer section name you specified in the EDMX file.

  6. 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.
  7. If the new entity data source appears, open the .edmx file in design view and refresh the design model.

Comments (14)

Ben

11/12/2011 5:24:23 PM
What do you mean in step 1? Do you mean create an EDMX file in Visual Studio 2005? Or, did you mean generate a script of the database from SQL Management tools?

Jason Skowronek

11/12/2011 7:15:28 PM
Ben, You should download the EDMX file I have provided, then add it to your project after you have made the necessary changes to it. It is for VS 2010, not 2005. I don't use VS 2005 anymore so I'm not sure if it will work or not. Email me if you have questions. Take care.

gattaca

11/13/2011 10:15:40 PM
Could you try it on EF 4.1(DbContext) ? I got an errer "Unable to load the specified metadata resource" If yours were work, please provide a vs2101 project with sql2000 mdf file

gattaca

11/13/2011 10:27:20 PM
Could you try in EF4.1(DbContext)?

Jason Skowronek

11/14/2011 4:54:25 PM
@gattaca. We haven't upgraded to 4.1 yet unfortunately so I am unsure this work-around will work for it. When we are able to upgrade I will provide an updated 4.1 package.

Jorge Ramirez

11/28/2011 4:04:55 PM
Hello Jason, I wanna say you Thanks!, this post is really helpfull. Could you give me your authorization for translate it to spanish and post it in my blog? I think this kind of information could be needed for everyone. Greetings from Colombia.

Jason Skowronek

11/28/2011 4:53:01 PM
Feel free to translate and use. I would ask that you link back to this article as a reference though. Take care.

ax0n

12/15/2011 12:40:17 PM
I'm using EF 4 and I get the same metadata exception as gattaca when I run the application ("Unable to load the specified metadata resource."). Any ideas?

Jason Skowronek

12/15/2011 5:20:22 PM
I'll run through my instructions again and provide more directions where there may be holes. Thanks for the feedback.

anty

1/15/2012 6:32:42 AM
open the edmx is show : error 0005: The 'http://schemas.microsoft.com/ado/2006/04/codegeneration:TypeAccess' attribute is not declared."

Jason

1/17/2012 10:38:37 PM
You need to make sure you modify your edmx file prior to including it in your project/solution. It will fail if you load it as-is.

OrangeHill

1/24/2012 8:22:05 PM
Hi Jason, thanks for your post it is being very helpful. I have a doubt, in step 7 you said "...if new data entity source appears..." what do we have to do it if it does not? Thanks.

Jason

1/24/2012 8:40:07 PM
Can you explain what you are seeing? I'll email you too.

OrangeHill

1/24/2012 9:11:52 PM
Thanks for your answer, I was not seeing any new datasource in the datasources panel. Then, comparing with another edmx files I was able to set a file with the correct names and information, now, I am able to see a new data source with the information in the file. However, when I open the edmx file in design view, (nothing is there) then I went to update model from DB and then it says me this SQL Server version is not supported. Sorry for the long comment, I tried to explain in detail what I am seeing here. Thanks
Leave a comment
Name *
Email *
Homepage
Comment

SkoNet provides comprehensive digital consulting services such as: web development, applications development, database design and architecture, business process management, customer relationship management, and many others that help businesses of every size, industry, and geography meet the complex challenge of managing and sharing information on the web. Our skills and expertise in online systems allow us to help customers build applications ranging from simple, single-page web sites to robust enterprise systems.

Online Backup, Ektron Consulting, Ektron Programmer, Ektron Developer, Ektron Partner Utah, Ektron Partner, Ektron Architect, Ektron Hosting, Salesforce.com Consultant Utah, Salesforce.com Partner Utah, Salesforce.com Partner, Salesforce.com Programmer, Salesforce.com Architect, Salesforce.com APEX Programmer