Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 29th, 2009, 06:40 AM
Authorized User
 
Join Date: Jul 2008
Location: , , South Africa.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to TashaAT
Default System.TypeInitializationException error

I am using

Beginning ASP.NET 2.0 e-commerce in C# 2005: from novice to professional

and on chapter four I get this error and I do not understand why? If anyone can please help!




System.TypeInitializationException was unhandled by user code
Message="The type initializer for 'ShopConfiguration' threw 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\GenericDat aAccess.cs:line 63
at CatalogAccess.GetDepartments() in c:\inetpub\wwwroot\Beadafrican\App_Code\CatalogAcc ess.cs:line 28
at UserControls_DepartmentsList.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\Beadafrican\UserControls\Depart mentsList.ascx.cs:line 22
at System.Web.Util.CalliHelper.EventArgFunctionCaller (IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Cal lback(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 dont see what is wrong? Here is the code if anyone can please assist it would be great!
GenericDataAccess.cs:
public static class GenericDataAccess
{
//static constructor
static GenericDataAccess()
{
//
// TODO: Add constructor logic here
//
}

//execute a command and returns the result as a DataTable Object
public static DataTable ExecuteSelectCommand(DbCommand command)
{
//The DataTable to be returned
DataTable table;

//Execute the command making sure the connection gets closed in the end
try
{
//open the data connection
command.Connection.Open();

//Execute the command and save the results in a DataTable
DbDataReader reader = command.ExecuteReader();
table = new DataTable();
table.Load(reader);

//Close the reader
reader.Close();
}
catch (Exception ex)
{
Utilities.LogError(ex);
throw ex;
}
finally
{
//Close the connection
command.Connection.Close();
}
return table;
}

//creates and prepares a new DbCommand object on a new connection
public static DbCommand CreateCommand()
{
//Obtain the database provider name
string dataProviderName = ShopConfiguration.DbProviderName;

//Obtain the database connection string
string connectionString = ShopConfiguration.DbConnectionString;

//Create a new data provider factory
DbProviderFactory factory = DbProviderFactories.GetFactory(dataProviderName);

//Obtain a database specific connection object
DbConnection conn = factory.CreateConnection();

//Set the connection string
conn.ConnectionString = connectionString;

//Create a database specific command object
DbCommand comm = conn.CreateCommand();

//Set the command type to stored procedure
comm.CommandType = CommandType.StoredProcedure;

//Return the initialised command object
return comm;
}




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 details into the DataList
protected void Page_Load(object sender, EventArgs e)
{
// don't reload data during postbacks

{
// CatalogAccess.GetDepartments returns a DataTable object containing
// department data, which is read in the ItemTemplate of the DataList
list.DataSource = CatalogAccess.GetDepartments();
// Needed to bind the data bound controls to the data source
list.DataBind();

}
}
}




Similar Threads
Thread Thread Starter Forum Replies Last Post
TypeInitializationException fezi786 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 February 5th, 2008 10:10 AM
System Error damnv General .NET 1 July 27th, 2005 02:47 AM
Deployment issue - TypeInitializationException eelisMX Pro VB.NET 2002/2003 0 March 31st, 2005 04:54 AM
system error 1157 preita Oracle 3 March 1st, 2005 01:37 PM
System.TypeInitializationException w connection fig000 ADO.NET 2 February 9th, 2004 06:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.