How to resolve Oracle error-"User Id' is an invalid connection string attribute"-using PowerShell?

1.3k Views Asked by At

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.

2

There are 2 best solutions below

0
KhorAMus On

Try to delete line breakes and space between ";" and "User Id".

0
Abdulaziz Burghal On

The connection string for Oracle has to be as the following:

"DataSource=Your_Database_Server_Name/database_name;User Id=your_database_username;Password=your_database_user_password"