日期:2014-05-18  浏览次数:20905 次

报错:用户代码未处理 EntityCommandExecutionException 该怎么处理?
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”的类型初始值设定项引发异常。

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