Idev Posted June 20, 2006 Posted June 20, 2006 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(); } } Quote
Administrators PlausiblyDamp Posted June 22, 2006 Administrators Posted June 22, 2006 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.