Skip to content Skip to sidebar Skip to footer

Entity Sqlce Can't Find Connection String In App.config File

I've been getting this error when I try and use my model container: No connection string named 'PFModelContainer' could be found in the application config file. I have my edmx

Solution 1:

If you are placing your edmx model in a separate class library, add an app.config to that class library and add the connection string to that config.

Additionally, if your datamodel resides inside a namespace then you will have to include the full namespace in your resource path:

For example, if you placed your edmx file in an assembly called MyProject.DataLayer and the namespace for the generated code is MyProject.DataLayer.DataModel, then your configuration string should be:

<addname="PFModelContainer"connectionString="metadata=res://*/DataModel.PFModel.csdl|res:
                           //*/DataModel.PFModel.ssdl|res://*/DataModel.PFModel.msl;
         provider=System.Data.SqlServerCe.3.5;
         provider connection string=&quot;
         Data Source=C:\Documents and Settings\Jon\My Documents\Visual
                     Studio 2010\Projects\SpreadsheetAddIn
                     \SpreadsheetAddIn\bin\Debug\PFData.sdf;
         Password=password&quot;"providerName="System.Data.EntityClient" />

Solution 2:

Got some help from experts exchange on this one. Ended up doing a work around (not sure why it wasn't working like it should), since I'm using DbContext instead of EntityObject I had to create my own overrideable procedure like (the second one below):

PublicSubNew()
   MyBase.New("name=PFModelContainer")
EndSubPublicSubNew(ByVal connectionString AsString)
   MyBase.New(connectionString)
EndSub

I then had to create my own connection string, which is basically what the original code generated, so, I'm not sure why it wasn't working from the app.config file. Maybe there's a bug in the program that will be fixed the next go around? Hopefully that was it, either that or I did something wrong, mystery.

Post a Comment for "Entity Sqlce Can't Find Connection String In App.config File"