CodeVerge.Net Beta


   Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > Asp.Net Forum > visual_studio.visual_studio_2005 Tags:
Item Type: Date Entered: 10/28/2009 7:34:15 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 0 Views: 7 Favorited: 0 Favorite
4 Items, 1 Pages 1 |< << Go >> >|
"Tasha1" <>
NewsGroup User
System.TypeInitializationException was unhandled by user code10/28/2009 7:34:15 AM

0

I am busy with an e-commerce web application using visual studio 2005 and IIS 7

I got this error

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




"Tasha1" <>
NewsGroup User
Re: System.TypeInitializationException was unhandled by user code10/30/2009 6:11:48 AM

0

Can anyone please help?


"Nishitha u" <>
NewsGroup User
Re: System.TypeInitializationException was unhandled by user code10/30/2009 6:46:36 AM

0

check this link.

http://social.msdn.microsoft.com/Forums/en/clr/thread/710269f5-3444-4ea1-bc18-9e3c177a2636 


Please remember to mark the replie(s) as answers if they help

Nishitha U
"Tasha1" <>
NewsGroup User
Re: System.TypeInitializationException was unhandled by user code10/30/2009 7:25:35 AM

0

Thanks for helping but unfortunately this is a Web Application and in the link you supplied it is a windows application

The Windows Form project is problematic only. Console application work fine.
(See bug with Bug ID FDBK40987, it is resolved but only for console application)


4 Items, 1 Pages 1 |< << Go >> >|




   
  Privacy | Contact Us
All Times Are GMT