The solution is to check for design mode. For example:
if(this.Site.DesignMode){
// do stuff here, but don't do a db connection
}
else{
// do your db stuff here
}
// do stuff here, but don't do a db connection
}
else{
// do your db stuff here
}
BUT the problem here is that DesignMode shouldn't be used in a constructor. It won't work. A great solution therefore is:
if(System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime){
// now you've detected DesignMode and it works if the check is even in a Constructor!
}
else{
// you can do your db stuff here
}
// now you've detected DesignMode and it works if the check is even in a Constructor!
}
else{
// you can do your db stuff here
}