1

This is my code to connect to an Oracle database:

[Reflection.Assembly]::LoadFile("E:\oracle\product\11.2.0\ODP.NET\bin\2.x\Oracle.DataAccess.dll")
$constr = "User Id=system;Password=password;Data Source=SERVER\INST"
$conn= New-Object Oracle.DataAccess.Client.OracleConnection($constr)

First line is working fine. I can see the assembly is loading and GAC is true.

Up to the second line there is no error.

But when it reaches the 3rd line, I am getting this error:

New-Object : Exception calling ".ctor" with "1" argument(s): "The type initializer for 'Oracle.DataAccess.Client.Oracle Connection' threw an exception. $conn= New-Object <<<< Oracle.DataAccess.Client.OracleConnection($constr) + CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand "

Can anybody advise me on this.

Powershell version is 2.

Update

PS I:\> [Reflection.Assembly]::LoadFile("E:\oracle\product\11.2.0\ODP.NET\bin\2.x\Oracle.DataAccess.dll")

GAC    Version        Location
---    -------        --------
True   v2.0.50727     C:\Windows\assembly\GAC_64\Oracle.DataAccess\2.112.3.0__89b483f429c47342\Oracle.DataAccess.dll

1 Answer 1

2

Oracle.DataAccess.dll is architecture specific. That means that you have to make sure the PowerShell process and the Oracle.DataAccess.dll assembly have the same bits (32 or 64).

May I suggest you to use the platform-independent Oracle managed driver? It works a lot better than the Oracle client specific Oracle.DataAccess.

Also see my answer here.

Sign up to request clarification or add additional context in comments.

7 Comments

I can't install anything on the server. Due to approval from other teams. GAC is showing True that means Oracle.DataAccess.dll is loading properly am i correct? On the server there are two version of Oracle.DataAccess.dll is available one is 2.x and another one is 4. I can load 2.x properly but i am not able to load 4.
Use the 2.0 version. I guess you have to install another client version to get it working then. Or use the managed version which is just copy/paste.
How would i know which is managed version. I am not a expert of Oracle
There is just one. Use the latest version. I have tested it to work on all recent versions.
So, what does that help? Did you try the managed driver? The only thing you can read is that it loads the 64-bits driver. I guess your process is 32-bit?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.