2016-06-07 48 views
1

我無法使用OTP .NET庫在Windows Server 2012計算機上從Powershell查詢Oracle。無法使用Powershell爲Oracle加載文件或程序集

我下載ODP.NET_Managed_ODAC12cR4.zip與

install_odpm.bat c:\oracle x64 false 

在我沒有安裝Oracle的服務器上安裝。

這條線:

Add-Type -Path "C:/oracle/odp.net/managed/common/Oracle.ManagedDataAccess.dll" 

或該行:

[System.Reflection.Assembly]::LoadFrom("C:/oracle/odp.net/managed/common/Oracle.ManagedDataAccess.dll") 

兩個給我下面的錯誤:

PS C:\temp> .\impoinftel.ps1 
Exception calling "LoadFrom" with "1" argument(s): "Could not load file or 
assembly 
'file:///C:\oracle\odp.net\managed\common\Oracle.ManagedDataAccess33.dll' or 
one of its dependencies. The system cannot find the file specified." 
At C:\temp\impoinftel.ps1:2 char:1 
+ [System.Reflection.Assembly]::LoadFrom("C:/oracle/odp.net/managed/common/Orac 
le. ... 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
~~~ 
    + CategoryInfo   : NotSpecified: (:) [], MethodInvocationException 
    + FullyQualifiedErrorId : FileNotFoundException 

New-Object : Cannot find type 
[Oracle.ManagedDataAccess.Client.OracleConnection]: make sure the assembly 
containing this type is loaded. 
At C:\temp\impoinftel.ps1:4 char:9 
+ $con = New-Object Oracle.ManagedDataAccess.Client.OracleConnection("User 
Id=byb ... 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
~~~ 
    + CategoryInfo   : InvalidType: (:) [New-Object], PSArgumentExcepti 
    on 
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewOb 
    jectCommand 

vcredist_x64.exe安裝在我的服務器

powershell.exe.c onfig如下:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <startup useLegacyV2RuntimeActivationPolicy="true"> 
     <supportedRuntime version="v4.0" />  
    </startup> 
</configuration> 

回答

0

您可能需要解鎖這個文件,所以只要進入「C:/oracle/odp.net/managed/common/Oracle.ManagedDataAccess.dll」,右鍵單擊它,並選擇「常規」下的「屬性」,選中「取消阻止」複選框(位於底部),然後單擊「應用」,然後單擊「確定」按鈕。

我在我的Windows 10中遇到了完全相同的問題,經過各種嘗試後,終於解決了這個問題。

相關問題