首页 > 代码库 > DbProviderFactories.GetFactory Oracle.ManagedDataAccess.Client

DbProviderFactories.GetFactory Oracle.ManagedDataAccess.Client

因为最近项目,要使用微软的EF框架不安装Oracle客户端的情况下,访问Oracle数据库。调用如下代码的时候会报错。

System.Data.Common.DbProviderFactories.GetFactory("Oracle.ManagedDataAccess.Client")

解决办法:

1、引用Oracle的:Oracle.ManagedDataAccess.dll

2、在APP.Config里面添加如下内容:

<configuration>  <system.data>    <DbProviderFactories>      <add name="OracleManagedDataAccess Data Provider"            invariant="Oracle.ManagedDataAccess.Client"            description=".Net Framework Provider for OracleManagedDataAccess"           type="Oracle.ManagedDataAccess.Client.OracleClientFactory,Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />    </DbProviderFactories>  </system.data></configuration>

3、其中的“Version=4.121.1.0”,根据你的版本修改。可以用Reflector查看。

4、通过如下代码,可以检查全部成功引入的DbProviderFactories

var factoryClasses = System.Data.Common.DbProviderFactories.GetFactoryClasses();var cols = factoryClasses.Columns;foreach (DataRow row in factoryClasses.Rows){    foreach (DataColumn col in cols)    {        Console.WriteLine("{0}:{1}", col.Caption, row[col.Caption]);    }    Console.WriteLine("-----------------------");}

 

http://www.ereader123.com/

DbProviderFactories.GetFactory Oracle.ManagedDataAccess.Client