I am busy with an e-commerce web application using visual studio 2005 and IIS 7
I got this error
System.TypeInitializationException failed to execute using user code
Message = "The type initializer for" ShopConfiguration "made an exception."
Source = "App_Code.r-ihwy-d"
TypeName = "ShopConfiguration"
Stacktrace:
at ShopConfiguration.get_DbProviderName() at GenericDataAccess.CreateCommand() in c:\inetpub\wwwroot\Beadafrican\App_Code\GenericDataAccess.cs:line 63 at CatalogAccess.GetDepartments() in c:\inetpub\wwwroot\Beadafrican\App_Code\CatalogAccess.cs:line 28 at UserControls_DepartmentsList.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\Beadafrican\UserControls\DepartmentsList.ascx.cs:line 22 at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
If I look at the code it refers to, I don’t see what is wrong? Here is the code, if anyone can help, it will be great!
GenericDataAccess.cs:
public static class GenericDataAccess {// static constructor static GenericDataAccess () {// // TODO: add constructor logic here //}
CatalogAccess.cs
public static class CatalogAccess {static CatalogAccess () {// // TODO: add constructor logic here //}
//Retrieve the list of departments public static DataTable GetDepartments() { //get configured DbCommand object DbCommand comm = GenericDataAccess.CreateCommand(); //set the stored procedure name comm.CommandText = "GetDepartments"; //execute the stored procedure and return the results return GenericDataAccess.ExecuteSelectCommand(comm); }
}
DepartementList.ascx.cs
public partial class UserControls_DepartmentsList: System.Web.UI.UserControl {// Load department data in DataList protected void Page_Load (object sender, EventArgs e) {// do not reload data during postbacks
{
}
class ShopConfiguration
{// Caches the connection string private static line readonly dbConnectionString;
static string dbProviderName;
//stores the number of products per page private readonly static int productsPerPage; //Stores the product description length for product lits private readonly static int productDescriptionLenght; //Store the name of your shop private readonly static string siteName; //Initialize various proeprties in the constructor static ShopConfiguration() { dbConnectionString = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString; dbProviderName = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ProviderName; productsPerPage = Int32.Parse(ConfigurationManager.AppSettings["ProductsPerPage"]); productDescriptionLenght = Int32.Parse(ConfigurationManager.AppSettings["ProductDescriptionLenght"]); siteName = ConfigurationManager.AppSettings["SiteName"]; } //Returns the connection string for BeadAfrican database public static string DbConnectionString { get { return dbConnectionString; } } //Returns the data provider name public static string DbProviderName { get { return dbProviderName; } }