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();
}
}
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();
}
}