如何解决oracle错误 - &quot“用户ID'无效的连接字符串属性“使用PowerShell?

发布于 2025-01-29 03:19:33 字数 1250 浏览 4 评论 0原文

我正在尝试使用PowerShell连接到远程Oracle DB。我安装了以下内容:

ODTwithODAC122011, ODP.Net_Managed_ODAC_122cR1

我有.netFramework 4.8.04084。

正如它在问题中所述的那样,我会收到以下错误:

New-Object : Exception calling ".ctor" with "1" argument(s): "'
User Id' is an invalid connection string attribute"

我尝试了几种连接到Oracle DB的方法。其中一个正在使用[System.Reflection.sembly] :: LoadWithPartialName(“ System.Data.oracleClient”)> loadWithPartialName(“ System.Reflection.sembly)),但这也会给出一个错误。

代码是:

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()

任何帮助都非常感谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你爱我像她 2025-02-05 03:19:33

尝试删除“断路”和“”之间的空间和“用户ID”。

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

原谅我要高飞 2025-02-05 03:19:33

Oracle的连接字符串必须如下:

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

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"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文