找不到请求的.Net Framework Data Provider。可能没有安装
作者:C/S框架网  发布日期:2017-09-22 15:57:57
  找不到请求的.Net Framework Data Provider。可能没有安装

经测试,使用DbProviderFactories.GetFactory(string providerInvariantName)方法
获取数据工厂必须在EXE主程序的App.config文件配置<system.data><DbProviderFactories>
否则会提示:找不到请求的.Net Framework Data Provider。可能没有安装!

使用DbProviderFactories.GetFactory方法需要配置数据库提供者:

1.配置 C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config 文件。

2.配置EXE主程序的app.config文件。



App.config文件配置参考


C# Code:

<system.data>
<DbProviderFactories>
<!--SQL Server数据库-->
<remove invariant="System.Data.SqlClient"/>
<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"/>

<!--Oracle 数据库-->
<remove invariant="System.Data.OracleClient"/>
<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"/>

<!--Oracle 数据库 (连接失败!.NET Framework2.0|x86??? )-->
<remove invariant="Oracle.DataAccess.Client"/>
<add name="Oracle Data Provider for .NET" invariant="Oracle.DataAccess.Client" description="Oracle Data Provider for .NET"
type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess, Version=2.112.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>

<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="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite"
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.58.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139"/>

<!--MySQL 数据库-->
<remove invariant="MySql.Data.MySqlClient"/>
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL"
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>

<!--Oracle 数据库-->
<remove invariant="Oracle.ManagedDataAccess.Client"/>
<add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver"
type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
</DbProviderFactories>
</system.data>

//来源:C/S框架网(www.csframework.com) QQ:1980854898


上一篇 下一篇