none
麻烦各位帮帮忙,百度很久都找不出答案。找不到请求的 .Net Framework 数据提供程序。可能没有安装。麻烦各位帮帮忙,百度很久都找不出答案 RRS feed

  • 问题

  • public static DbCommand CreateCommand()
        {
            // Obtain the database provider name
            string dataProviderName = CanteenConfiguration.DbProviderName;
            // Obtain the database connection string
            string connectionString = CanteenConfiguration.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;

    下面是我的machine.config设置

    <DbProviderFactories>
       <add name="Odbc Data Provider" invariant="System.Data.Odbc" description=".Net Framework Data Provider for Odbc" type="System.Data.Odbc.OdbcFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
       <add name="OleDb Data Provider" invariant="System.Data.OleDb" description=".Net Framework Data Provider for OleDb" type="System.Data.OleDb.OleDbFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
       <add name="OracleClient Data Provider" invariant="System.Data.OracleClient" description=".Net Framework Data Provider for Oracle" type="System.Data.OracleClient.OracleClientFactory, System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
       <add name="SqlClient Data Provider" invariant="System.Data.SqlClient" description=".Net Framework Data Provider for SqlServer" type="System.Data.SqlClient.SqlClientFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
       <add name="Microsoft SQL Server Compact Data Provider" invariant="System.Data.SqlServerCe.3.5" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
       <add name="SQL Server CE Data Provider" invariant="Microsoft.SqlServerCe.Client" description=".NET Framework Data Provider for Microsoft SQL Server 2005 Mobile Edition" type="Microsoft.SqlServerCe.Client.SqlCeClientFactory, Microsoft.SqlServerCe.Client, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
       <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=5.0.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
      </DbProviderFactories>

    <connectionStrings>
      <add name="CanteenConnection" connectionString="Server=(local)\SqlExpress;  Database=Canteen; User=canteen; Password=ecommerce" providerName="System.Data.Sqlclient"/>
     </connectionStrings>

    我还有一个项目也用到上面的代码了  DbProviderFactory factory = DbProviderFactories.GetFactory(dataProviderName); 可是可以运行!!!这是为什么??


    2012年10月8日 1:08

答案

  • 你的dataProviderName名称是什么?你的2个程序是在一台机器上运行的吗?调用的都是同一个Provider?

    错误信息大概是你调用的程序没有安装驱动,如

    .Net Framework Data Provider for MySQL

    就需要单独安装才能使用的



    【孟子E章】


    2012年10月10日 3:47
    版主