Question posted 2009 · +5 upvotes
I’m experimenting with the Entity Framework and I want to connect to an Access 2007 database.
The following code is inspired by http://msdn.microsoft.com/en-us/library/system.data.entityclient.entityconnection.connectionstring.aspx
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());
ec.Open();
ec.Close();
The EntityConnectionStringBuilder tells me that it doesn’t support the DataSource property. I can connect fine with ADO.net so I know that the path and the provider are correct.
Is this just the complete wrong approach?
Accepted answer +13 upvotes
The approach you are using to build the EF connection string is correct.
BUT…
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
Alex
(Entity Framework Team, Microsoft)
Top ms-access Q&A (6)
- How can I modify a saved Microsoft Access 2007 or 2010 Import Specification? +31 (2008)
- OleDbCommand parameters order and priority +28 (2009)
- Is there an equivalent to the SUBSTRING function in MS Access SQL? +26 (2009)
- What do I need to read Microsoft Access databases using Python? +25 (2009)
- MS Access library for python +24 (2009)
- is there any replacement of Access? +21 (2009)
ms-access solutions on this site
— top 24%.