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

4
  • possible duplicate of Wait! which config file? (Entity Framework Connection String) Commented Dec 8, 2014 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 Commented Dec 9, 2014 at 5: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. Commented Dec 9, 2014 at 5: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 Commented Dec 9, 2014 at 6:19

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
could you plz add the code where you create your Entities context instance
1

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

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.