Exception calling ".ctor" while connecting to an Oracle database (ODP.net)

This is my code to connect to an Oracle database:

$constr = "User Id=system;Password=password;Data Source=SERVERINST"
$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.

Source: oracle

Leave a Reply