Error "Failed to create the ControlName component when dragging windows creating a user control onto the form

I have user window controls in my project. He works on the form without any problems, but suddenly I can no longer use it in any other form. If I try to drag it from the toolbar to a new form, I get this error message

"The controlName could not be created. The error message is: system.ArgumentException: The specified named connection is either not found in the configuration, is not intended for use with the EntityClient provider, or is invalid."

But when I run the project, it compiles without any errors.

In addition, when I want to open the constructor of a form that already contains this Usercontrol and works well, the constructor does not load, and I see error messages below

"To prevent possible data loss before loading the constructor, the following errors must be resolved:

The specified named connection is either not in the configuration, is not intended to be used with the EntityClient provider, or is invalid.

The variable "MyControlName1" is either not declared or has never been assigned. "

i'M does not understand what is happening, but the project is still building and working, but definitely something is seriously wrong.

+4
source share
2 answers

It looks like your control is trying to establish a connection to the database by development time, and the database cannot be found (probably because the designer is trying to look in the bin directory in Visual Studio).

It’s best not to connect the database to the user element at design time, but to dynamically bind it at run time.

+1
source

Exchange your boot methods with:

private void myUserControl_Load(object sender, EventArgs e) { if (!this.DesignMode) { //....stuff } } 
+1
source

All Articles