Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I created a form that uses Enterprise Library - DAAB - version Jan 2006 to access the DB in its constructor. Everything works fine; however, when I created a UserControl that attempts to store that form as a variable, the VS 2005 designer will not let me drag that UserControl onto a new form. It gives me the following error:

 

 

�Failed to create component �UserControl�. The error message follows: �System.NullReferenceException: Object reference not set to an instance of object. At Microsoft.Practices.EnterpriseLibrary.Data.DatabaseConfigurationView.get_DefaultName(), at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseMapper.MapName(String name, IConfigurationSource configSource)��. "

 

 

Everything compiles successfully without errors; however, I am unable to drag the UserControl on any forms. After debugging, I found that the error is caused by the line �Database db = DatabaseFactory.CreateDatabase();�

 

I feel that being able to store forms that use DAAB inside UserControls is a reasonable requirement.

 

 

Any help would be appreciated! Thanks in advance!

 

 

Below is the relevant code:

 

public partial class SampleControl : UserControl

{

private ProductForm subForm = new ProductForm();

public SampleControl ()

{

InitializeComponent();

}

}

 

public partial class ProductForm : Form

{

public ProductForm()

{

InitializeComponent();

AccessDB();

}

private void AccessDB()

{

//THIS LINE CAUSES THE DESIGNER ERROR

Database db = DatabaseFactory.CreateDatabase();

}

}

  • Administrators
Posted

Is the UserControl part of the same project as the form or is it a differerent project?

 

Also check your config files are correct - it could be failing to load it's configuration at design time and failing...

 

It may be worth wrapping the call to .CreateDatabase in a check and only run when not being called from the designer.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...