Exception calling "Open" with "0" argument(s): "ORA-12545: Network Transport: Unable to resolve conn

Copper Contributor

Hi , 

I am getting the below Error while trying to connect to the database i am unable to find the issue can some one help to resolve this issue. ..


#Oracle Database Connection
$username="USERNAME"
$Password="PASSWORD"
Add-Type -Path "D:\ORACLE\product\12.1.0\dbhome_1\ODP.NET\managed\common\Oracle.ManagedDataAccess.dll"
$path="F:\Scripts\NEW_TEST"
$serversfile="$Path\servers.txt"
$serverslist = get-content FileSystem::$serversfile
$serverslist
foreach( $server in $serverslist)
{
$connectionString = "Data Source=(DESCRIPTION=(ADDRESS = (PROTOCOL = TCP)(HOST = $server.mgroupnet.com)(PORT = 1521))(CONNECT_DATA=(SID = $server)(GLOBAL_NAME = $server.WORLD)));User Id=$username;Password=$password;"
#$connectionString = "Data Source=test;User Id=$username;Password=$password;"
$connectionString
#Select the columns you want from the Oracle Database
$query1 = "SELEct name from v`$database;"
$connection = New-Object Oracle.ManagedDataAccess.Client.OracleConnection("$connectionString")
$connection.open()
TRY
{
$command1 = New-Object Oracle.ManagedDataAccess.Client.OracleCommand
$command1.Connection = $connection
$command1.CommandText = $query1
$ds1 = New-Object system.Data.DataSet
$da1 = New-Object Oracle.ManagedDataAccess.Client.OracleDataAdapter($command1)
[void]$da1.fill($ds1)
[System.Data.DataTable]$query1result = $ds1.Tables[0]

}

catch {
Write-Error (“Database Exception: {0}`n{1}” -f `
$connnection.ConnectionString, $_.Exception.ToString())
}

 

Regards,

Raj

1 Reply
I am not expert on this oracle things, but lets give it a try.
base on the error, It seems that the issue is in the $serverslist.
the server name is not resolvable via DNS, try to replace the server name by IP address
also I don't know if you are using the tnsname.ora, also make sure its configured correctly