看起来 Oracle Universal Installer 12.2 中有一个错误,它没有注册 ODP.NET 组件。您可以运行下面的脚本(根据您的系统修改文件夹名称)以正确配置它们。
set Oracle_x64=c:\oracle\product\12.1\Client_x64\odp.net
set OraProvCfg_x64=%Oracle_x64%\bin\4\OraProvCfg.exe
set Oracle_x86=c:\oracle\product\12.1\Client_x86\odp.net
set OraProvCfg_x86=%Oracle_x86%\bin\4\OraProvCfg.exe
set TNS_ADMIN=C:\oracle\network\admin
IF EXIST "%Oracle_x64%\managed\common\Oracle.ManagedDataAccess.dll" "%OraProvCfg_x64%" /action:gac /providerpath:%Oracle_x64%\managed\common\Oracle.ManagedDataAccess.dll
IF EXIST "%Oracle_x64%\managed\PublisherPolicy\4\Policy.4.121.Oracle.ManagedDataAccess.dll" "%OraProvCfg_x64%" /action:gac /providerpath:%Oracle_x64%\managed\PublisherPolicy\4\Policy.4.121.Oracle.ManagedDataAccess.dll
IF EXIST "%Oracle_x64%\managed\PublisherPolicy\4\Policy.4.122.Oracle.ManagedDataAccess.dll" "%OraProvCfg_x64%" /action:gac /providerpath:%Oracle_x64%\managed\PublisherPolicy\4\Policy.4.122.Oracle.ManagedDataAccess.dll
IF EXIST "%Oracle_x64%\managed\common\Oracle.ManagedDataAccess.dll" "%OraProvCfg_x64%" /action:config /product:odpm /frameworkversion:v4.0.30319 /providerpath:%Oracle_x64%\managed\common\Oracle.ManagedDataAccess.dll /set:settings\TNS_ADMIN:%TNS_ADMIN%
IF EXIST "%Oracle_x86%\managed\common\Oracle.ManagedDataAccess.dll" "%OraProvCfg_x86%" /action:config /product:odpm /frameworkversion:v4.0.30319 /providerpath:%Oracle_x86%\managed\common\Oracle.ManagedDataAccess.dll /set:settings\TNS_ADMIN:%TNS_ADMIN%
rem Oracle.ManagedDataAccessDTC was used in earlier versions, not used anymore
"%OraProvCfg_x64%" /action:ungac /providerpath:Oracle.ManagedDataAccessDTC
IF EXIST "%Oracle_x64%\bin\2.x\Oracle.DataAccess.dll" "%OraProvCfg_x64%" /action:gac /providerpath:%Oracle_x64%\bin\2.x\Oracle.DataAccess.dll
IF EXIST "%Oracle_x64%\PublisherPolicy\2.x\Policy.2.102.Oracle.DataAccess.dll" "%OraProvCfg_x64%" /action:gac /providerpath:%Oracle_x64%\PublisherPolicy\2.x\Policy.2.102.Oracle.DataAccess.dll
IF EXIST "%Oracle_x64%\PublisherPolicy\2.x\Policy.2.111.Oracle.DataAccess.dll" "%OraProvCfg_x64%" /action:gac /providerpath:%Oracle_x64%\PublisherPolicy\2.x\Policy.2.111.Oracle.DataAccess.dll
IF EXIST "%Oracle_x64%\PublisherPolicy\2.x\Policy.2.112.Oracle.DataAccess.dll" "%OraProvCfg_x64%" /action:gac /providerpath:%Oracle_x64%\PublisherPolicy\2.x\Policy.2.112.Oracle.DataAccess.dll
IF EXIST "%Oracle_x64%\PublisherPolicy\2.x\Policy.2.121.Oracle.DataAccess.dll" "%OraProvCfg_x64%" /action:gac /providerpath:%Oracle_x64%\PublisherPolicy\2.x\Policy.2.121.Oracle.DataAccess.dll
IF EXIST "%Oracle_x64%\PublisherPolicy\2.x\Policy.2.122.Oracle.DataAccess.dll" "%OraProvCfg_x64%" /action:gac /providerpath:%Oracle_x64%\PublisherPolicy\2.x\Policy.2.122.Oracle.DataAccess.dll
IF EXIST "%Oracle_x64%\bin\4\Oracle.DataAccess.dll" "%OraProvCfg_x64%" /action:gac /providerpath:%Oracle_x64%\bin\4\Oracle.DataAccess.dll
IF EXIST "%Oracle_x64%\PublisherPolicy\4\Policy.4.112.Oracle.DataAccess.dll" "%OraProvCfg_x64%" /action:gac /providerpath:%Oracle_x64%\PublisherPolicy\4\Policy.4.112.Oracle.DataAccess.dll
IF EXIST "%Oracle_x64%\PublisherPolicy\4\Policy.4.121.Oracle.DataAccess.dll" "%OraProvCfg_x64%" /action:gac /providerpath:%Oracle_x64%\PublisherPolicy\4\Policy.4.121.Oracle.DataAccess.dll
IF EXIST "%Oracle_x64%\PublisherPolicy\4\Policy.4.122.Oracle.DataAccess.dll" "%OraProvCfg_x64%" /action:gac /providerpath:%Oracle_x64%\PublisherPolicy\4\Policy.4.122.Oracle.DataAccess.dll
IF EXIST "%Oracle_x86%\bin\2.x\Oracle.DataAccess.dll" "%OraProvCfg_x86%" /action:gac /providerpath:%Oracle_x86%\bin\2.x\Oracle.DataAccess.dll
IF EXIST "%Oracle_x86%\PublisherPolicy\2.x\Policy.2.102.Oracle.DataAccess.dll" "%OraProvCfg_x86%" /action:gac /providerpath:%Oracle_x86%\PublisherPolicy\2.x\Policy.2.102.Oracle.DataAccess.dll
IF EXIST "%Oracle_x86%\PublisherPolicy\2.x\Policy.2.111.Oracle.DataAccess.dll" "%OraProvCfg_x86%" /action:gac /providerpath:%Oracle_x86%\PublisherPolicy\2.x\Policy.2.111.Oracle.DataAccess.dll
IF EXIST "%Oracle_x86%\PublisherPolicy\2.x\Policy.2.112.Oracle.DataAccess.dll" "%OraProvCfg_x86%" /action:gac /providerpath:%Oracle_x86%\PublisherPolicy\2.x\Policy.2.112.Oracle.DataAccess.dll
IF EXIST "%Oracle_x86%\PublisherPolicy\2.x\Policy.2.121.Oracle.DataAccess.dll" "%OraProvCfg_x86%" /action:gac /providerpath:%Oracle_x86%\PublisherPolicy\2.x\Policy.2.121.Oracle.DataAccess.dll
IF EXIST "%Oracle_x86%\PublisherPolicy\2.x\Policy.2.122.Oracle.DataAccess.dll" "%OraProvCfg_x86%" /action:gac /providerpath:%Oracle_x86%\PublisherPolicy\2.x\Policy.2.122.Oracle.DataAccess.dll
IF EXIST "%Oracle_x86%\bin\4\Oracle.DataAccess.dll" "%OraProvCfg_x86%" /action:gac /providerpath:%Oracle_x86%\bin\4\Oracle.DataAccess.dll
IF EXIST "%Oracle_x86%\PublisherPolicy\4\Policy.4.112.Oracle.DataAccess.dll" "%OraProvCfg_x86%" /action:gac /providerpath:%Oracle_x86%\PublisherPolicy\4\Policy.4.112.Oracle.DataAccess.dll
IF EXIST "%Oracle_x86%\PublisherPolicy\4\Policy.4.121.Oracle.DataAccess.dll" "%OraProvCfg_x86%" /action:gac /providerpath:%Oracle_x86%\PublisherPolicy\4\Policy.4.121.Oracle.DataAccess.dll
IF EXIST "%Oracle_x86%\PublisherPolicy\4\Policy.4.122.Oracle.DataAccess.dll" "%OraProvCfg_x86%" /action:gac /providerpath:%Oracle_x86%\PublisherPolicy\4\Policy.4.122.Oracle.DataAccess.dll
更新
根据Oracle Doc ID 2272241.1,这似乎是有意的:
适用于:适用于
.NET 的 Oracle 数据提供程序 - 版本 12.1.0.2 及更高版本
Microsoft Windows x64(64 位)
Microsoft Windows(32 位)
症状
为 .Net 安装 12.2 Oracle 数据提供程序时,提供程序不会自动在全局程序集缓存 (GAC) 中注册。
更改
为 .Net 的 Oracle Provider 的 12.2 版本
原因
这是预期的行为。由于如此多的环境同时使用多个版本的 ODP.Net,从 12.2 开始,默认情况下,安装程序不会自动在 GAC 中注册 ODP.Net 提供程序。
解决方案
按照文档 ID 1169890.1 中所述手动将 dll 注册到 GAC:HOWTO:使用 OraProvCfg.exe 的示例从全局程序集缓存中添加/删除 Oracle 程序集
但是,我认为这是一个错误。并行运行多个版本的 ODP.Net 是相当困难的,因为版本必须与Oracle 客户端的版本完全Oracle.DataAccess.dll
匹配。安装多个 Oracle 客户端(即 64 位和 32 位各一个以上)通常会导致很多问题,而且并不常见。