我正在尝试使用PowerShell更改Oracle帐户。 .net DLL似乎不支持包含“更改用户”命令的Oracle SQL。我收到以下输出/错误:
Trying to connect to Database instance on NIMHDDEV...Success.
SELECT ALL_USERS
SYS
Exception calling "ExecuteNonQuery" with "0" argument(s): "ORA-00922: missing or invalid option
下面是用于测试的PowerShell。
[System.Reflection.Assembly]::LoadWithPartialName("System.Data.OracleClient")
$objOracleConnection = New-Object System.Data.OracleClient.OracleConnection
$ds="Data Source=$ServerName; User ID=$login; Password=$password; Integrated Security=No"
$objOracleConnection.ConnectionString = $ds
Write-Host "Trying to connect to Database instance on $ServerName..." -NoNewline
$objOracleConnection.Open()
Write-Host "Success."
$sql = "SELECT * FROM ALL_USERS"
$cmd = New-Object System.Data.OracleClient.OracleCommand($sql, $objOracleConnection)
$cmd.ExecuteScalar()
$sql = 'ALTER USER Account unlock'
$cmd = New-Object System.Data.OracleClient.OracleCommand($sql, $objOracleConnection)
$cmd.ExecuteNonQuery()