Am I crazy for using Entity Framework with an OleDB connection?

c# entity-framework ms-access


I'm experimenting with the Entity Framework and I want to connect to an Access 2007 database.

The following code is inspired by

I suspect that I've got the wrong end of the stick...

OleDbConnectionStringBuilder oledbConn = new OleDbConnectionStringBuilder();

oledbConn.DataSource = @"..\..\..\..\Pruebas.accdb"; //yep Access 2007!

EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder ();
entityBuilder.Provider = "Microsoft.ACE.OLEDB.12.0";
entityBuilder.ConnectionString = oledbConn.ToString();
EntityConnection ec = new EntityConnection(entityBuilder.ToString());

The EntityConnectionStringBuilder tells me that it doesn't support the DataSource property. I can connect fine with so I know that the path and the provider are correct.

Is this just the complete wrong approach?

7/15/2009 5:14:48 PM

Accepted Answer

The approach you are using to build the EF connection string is correct.


The Entity Framework only works with Providers (i.e. SqlClient) that support something called provider services.

The OleDB provider doesn't support 'Provider Services' so you can't use EF with the OleDb (unless you can find a third party OleDb provider with support for EF).

Hope this helps


(Entity Framework Team, Microsoft)

7/16/2009 5:47:55 AM

Popular Answer

To build your connection string create a file on your desktop called a.udl

Double click on it, should open a UI. Follow the wizard, test the connection.

Then close the UI, open the file with notepad, and you have your connection string.

EDIT It may be that you are getting this error because your are missing a refernce. Entity Framework uses extension methods. Therefore, it might compile but still not work.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow