I have a problem with configuring an EDMX file that lives in an other assembly than by web project. My project looks somewhat like this:
Project 1 --> Database.edmx --> App.Config Project 2 --> Ton's of .cs and .aspx files. --> Web.Config with the proper connection string.
Inside Visual Studio the updating of the .EDMX file inside Project 1 goes smoothly and while I had the .EDMX file inside project 2 the application ran as it supposed to.
Anyone has an idea on how to configure the .EDMX file inside Project 1 to point to the connectionstring of Web.Config? (or should I use Project1.dll.config to configure Project 1?)
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
You have to change the
* in the connection string for the assembly name where the .edmx files are in:
<add name="Entities" connectionString="metadata=res://*/Models.EF.Model.csdl|res://*/Models.EF.Model.ssdl|res://*/Models.EF.Model.msl;provider=System.Data.SqlClient;provider connection ... ;" providerName="System.Data.EntityClient" />
<add name="Entities" connectionString="metadata=res://Project2/Models.EF.Model.csdl|res://Project2/Models.EF.Model.ssdl|res://Project2/Models.EF.Model.msl;provider=System.Data.SqlClient;provider connection ... ;" providerName="System.Data.EntityClient" />
As it turned out, there were 2 problems. One was solved replacing the * in the connection string.
The second problem was the one described here: http://blogs.teamb.com/craigstuntz/2010/08/13/38628/
It had to do with the path .csdl, .ssdl and .msl files had as resources inside the Project1 assembly
Anyway, things function properly now
Easier way is to take connection string from Web.Config and copy them into App.Config and point EDMX’s connectionstring to same DB information. e.g
<connectionStrings> <add name="ApplicationServices" connectionString="data source=.SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" /> <add name="aspnetdbEntities" connectionString="metadata=res://*/Data.PSBData.csdl|res://*/Data.PSBData.ssdl|res://*/Data.PSBData.msl;provider=System.Data.SqlClient;provider connection string="data source=.SQLEXPRESS;attachdbfilename=|DataDirectory|aspnetdb.mdf;integrated security=True;user instance=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /> </connectionStrings>
Also you need to check if the namespaces are correct if you have moved Database.edmx from Project 2 to Project 1, which you can check by opening Database.edmx and goto code behind.