C# 代码:.cs文件里面的
public static DbCommand CreateCommand()
    {
        // Obtain the database provider name
        string dataProviderName = WebSiteConfiguration.DbProviderName;
        // Obtain the database connection string
        string connectionString = WebSiteConfiguration.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 initialized command object
        return comm;
    }WebSiteConfiguration”的类型初始值设定项引发异常。

解决方案 »

  1.   

    可能是WebSiteConfiguration.DbProviderName;
    中为DbProviderName属性赋值的时候可能从配置文件读设置,但是配置配置文件中可能没有设置,检查一下配置文件
      

  2.   

    已经设置了的也不行,那里提示的是:“WebSiteConfiguration”的类型初始值设定项引发异常。是因为“WebSiteConfiguration”的类型初始值设定错误吗?应该怎么改呢?
      

  3.   

    我刚刚无意之中解决了,现在也没有找到具体为什么,太高兴了,可能你有多份配置文件,还有数据连接,这些都需要在WEB.CONFIG里面在复写一次