3

I have a project solution consisting of two class libraries and a Windows Application. The two libraries are split into Custom_Classes and Custom_Controls.

Im my Custom_Classes library I have a entity model that is referenced from my Custom_Controls library to access certain data members. The connections work fine and when I add a control to my windows form it does not have any problems. But when I want to add a custom control inside another one dragging it from the toolbox the following message appears.

Failed to create component 'u_Settings'. The error message follows: ' No connection string named 'MyEntitiesCon' could not be found in the application config file.'

I have made sure that the connection string is in the app.config file and even tried adding it in the project settings file. Here is my connection string copied from the Custom_Classes project to the Custom_Controls project

<connectionStrings>
    <add name="MyEntitiesCon" connectionString="metadata=res://*/Enity_Framework.SP_Model.csdl|res://*/Enity_Framework.SP_Model.ssdl|res://*/Enity_Framework.SP_Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=XXX\XXX;initial catalog=XXX;integrated security=True;connect timeout=30;connectretrycount=2;MultipleActiveResultSets=True;App=EntityFramework&quot;"      providerName="System.Data.EntityClient" />
</connectionStrings>

I have tried a bunch of solutions but with no success

Juan Gous
  • 249
  • 1
  • 2
  • 20
  • possible duplicate of [Wait! which config file? (Entity Framework Connection String)](http://stackoverflow.com/questions/6223223/wait-which-config-file-entity-framework-connection-string) – Nathan Tuggy Dec 08 '14 at 14:39
  • I tried removing the app.config file in the Custom_Controls project and leave the only reference to MyEntitiesCon in Custom_Classes but is still gives me the same error – Juan Gous Dec 09 '14 at 05:45
  • You need to make sure the connection string is present with the right name in the config file for the application, not *either* of the libraries, per that link. – Nathan Tuggy Dec 09 '14 at 05:48
  • 1
    Sorry if I am not understanding correctly. What you are saying is delete both the app.config files in the libraries and only use the app.config in the windows application. If that is the case then it is not working because I am not working in the application, I am adding controls to control in the Custom_Controls Library – Juan Gous Dec 09 '14 at 06:19

3 Answers3

1

Firstly this seems like a bad design, braking SOLID principles. You should depend on abstract DataSource interface. The datasource implementation should be separated from the control.

There's nice guideline at MSDN too:

http://msdn.microsoft.com/en-us/library/ms171926.aspx

PS. Open the EF designer and try to update the model. Save the connection string and copy it to the project where you design your controls.

Andrew
  • 3,648
  • 1
  • 15
  • 29
  • I dont think your answer solves my issue. There is no problem with my EF model because when I use it in the Application and the Custom_Controls library there are no issues. The issue only comes in when I put a usercontrol inside another usercontrol that is gives me that error. – Juan Gous Dec 11 '14 at 14:39
  • could you plz add the code where you create your Entities context instance – Andrew Dec 11 '14 at 15:01
1

Have you tried adding the connection string to the app.config in the Windows application project?

Ryan
  • 89
  • 1
  • 7
0

If designer's initialization needs the connection string then you you need to put the connection string to every new project's config that uses your control library. By the way if you remove your connection string from designer initialization then you only need to put it on the destination's config file.

M.G.E
  • 371
  • 1
  • 10