I am trying to connect to a remote Oracle db using PowerShell. I installed the following:
ODTwithODAC122011, ODP.Net_Managed_ODAC_122cR1
I have .NetFramework 4.8.04084.
As it states in the question, I get the following error:
New-Object : Exception calling ".ctor" with "1" argument(s): "'
User Id' is an invalid connection string attribute"
I have tried a few different ways of connecting to the Oracle db. One of them being loading the assembly using [System.Reflection.Assembly]::LoadWithPartialName("System.Data.OracleClient") but that gives an error too.
Code is:
Add-Type -Path C:\odp.net\managed\common\Oracle.ManagedDataAccess.dll
$query="Select NC_NAME From NC_PROGRAMS FETCH FIRST 10 ROWS ONLY"
$OracleConnectionString = "Data Source=(DESCRIPTION=
(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.xx.xx.x)(PORT=1521)))
(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=Fa1)));
User Id=username ;Password=password"
$connection = New-Object Oracle.ManagedDataAccess.Client.OracleConnection($OracleConnectionString)
$connection.open()
$command=$connection.CreateCommand()
$command.CommandText=$query
$reader=$command.ExecuteReader()
while ($reader.Read()) {
$reader.GetString(1) + ', ' + $reader.GetString(0)
}
$connection.Close()
Any help is greatly appreciated.
Try to delete line breakes and space between ";" and "User Id".