Need connect to the database and get some values inside the Load event of my user controller. But I'm getting a null reference error when every time I drag and drop my user control to a windows form. It seems like visual studio is unable to initialize the connection string in the design time(according to stack trace ) .Connection string has been defined inside the app.config file. So far I googled this error and tried adding following code block but couldn't work.
if(System.ComponentModel.LicenseManager.UsageMode != System.ComponentModel.LicenseUsageMode.Designtime)
{
_strcon = ConfigurationManager.ConnectionStrings["defaultConnection"].ConnectionString;
}
Connection String
<add name="defaultConnection"
providerName="System.Data.SqlClient" connectionString="Dbhostname;Initial Catalog=employee;User ID=sa;Password=password;Enlist=False;MultipleActiveResultSets=true;" />
There is no any compile time errors or run time errors. The error is windows form designer is not loading