Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Oracle ODBC connection using DSN with powershell

$
0
0

 

Hi All,

I want to establish a Oracle database connection using ODBC DSN. I have written the below code but i am getting error "Data source name not found and no default driver
specified
". Let me know what needs to be modified or added to establish this connection successfully.

I have created a system DSN : test_odbc in ODBC administrator

Script:

[System.Reflection.Assembly]::LoadWithPartialName("System.Data.OracleClient")
$conn = New-Object System.Data.Odbc.OdbcConnection
$conn.connectionstring = "Provider=System.Data.OracleClient;(Oracle in v112030b64;DSN=test_odbc)"
$conn.open()
$sql = "select * from products"
$cmd = New-Object system.Data.Odbc.OdbcCommand($sql,$conn)
$da = New-Object system.Data.Odbc.OdbcDataAdapter($cmd)
$dt = New-Object system.Data.datatable
$null = $da.fill($dt)
$conn.close()
$dt

 

Error:  Exception calling "Open" with "0" argument(s): "ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver
specified"
At line:4 char:1
+ $conn.open()
+ ~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : OdbcException


Viewing all articles
Browse latest Browse all 6937

Trending Articles