我使用以下命令:
我C:\oracle
安裝ODAC1120320Xcopy_x64.zip(見新版本here)
下面是一個snipet ExecuteReader()
你也可以使用ExecuteNonQuery()
# Load Oracle assembly
Add-Type -Path "C:\oracle\odp.net\bin\4\Oracle.DataAccess.dll"
$compConStr = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.213.6.15)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=OURSERVICENAME)));User Id=User;Password=Pass;Pooling=False"
# Establish the connexion
$oraConn= New-Object Oracle.DataAccess.Client.OracleConnection($compConStr)
$oraConn.Open()
$sql1Tpl = @"
SELECT masi.yyyy as TYPE_ID FROM xxxx masi
WHERE masi.serno = '{0}'
"@
$sql1 = $sql1Tpl -replace "blabla"
# Exécution
$command1 = New-Object Oracle.DataAccess.Client.OracleCommand($sql1,$oraConn)
$command1.CommandTimeout = 1500
$reader1 =$command1.ExecuteReader()
$clocationID = $null
if ($reader1.HasRows -eq $true)
{
$read =$reader1.read()
if ($read -eq $true)
{
$clocationID = $reader1["C_LOCATION_ID"]
}
}
# Close the reader
$reader1.close()
# Disconect
$oraConn.Close()
哪個供應商你使用ODAC嗎? (它提供了幾個) –
嗨Wenfried。它是ODAC 11.2 64位 – btecndcomp
哪個提供者/驅動程序? 「ODBC」,「OLE DB」,「ODP.NET」或「ODP.NET託管驅動程序」? –