[ACCEPTED]-Entity Framework with OleDB connection - am I just plain nuts?-ms-access
The approach you are using to build the 9 EF connection string is correct.
BUT...
The 8 Entity Framework only works with Providers 7 (i.e. SqlClient) that support something 6 called provider services.
The OleDB provider 5 doesn't support 'Provider Services' so you 4 can't use EF with the OleDb (unless you 3 can find a third party OleDb provider with 2 support for EF).
Hope this helps
Alex
(Entity 1 Framework Team, Microsoft)
I'm not sure you have either end of the 14 stick. :)
Check out this example instead. There might 13 be other issues with your code, but it looks 12 like you're setting the entity builder's 11 ConnectionString property when you need 10 to be setting its ProviderConnectionString property (among other 9 properties).
It seems to me that for something 8 called a "connection string builder", the 7 ConnectionString property should be read-only 6 (it's not). I guess it's intended to also 5 double as a connection string parser.
Edit: I 4 just looked at your code again, and I think 3 all you have to do is change ConnectionString 2 to ProviderConnectionString. You may have 1 the stick after all!
To build your connection string create a 9 file on your desktop called a.udl
Double 8 click on it, should open a UI. Follow the 7 wizard, test the connection.
Then close the 6 UI, open the file with notepad, and you 5 have your connection string.
EDIT It may be that 4 you are getting this error because your 3 are missing a refernce. Entity Framework 2 uses extension methods. Therefore, it might 1 compile but still not work.
Probably OleDb does not work with EF but 3 the initialization works fine if you set 2 the entityBuilder and the oledbConn in this 1 way.
OleDbConnectionStringBuilder oledbConn = new OleDbConnectionStringBuilder();
oledbConn.Provider = "Microsoft.Jet.OLEDB.4.0";
oledbConn.DataSource = @"C:\Users\Utente\Documents\visual studio 2013\Projects\How to implement the1\Debug\Test.mdb";
EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();
entityBuilder.Provider = "System.Data.EntityClient";
string connectionString = string.Format("metadata=res://*/School.csdl|res://*/School.ssdl|res://*/School.msl;provider=System.Data.OleDb;provider connection string='{0}'", oledbConn);
entityBuilder.ConnectionString = connectionString;
EntityConnection ec = new EntityConnection(entityBuilder.ToString());
ec.Open();
ec.Close();
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.