Connect using ODBC and read from PowerShell

Hi
The Quick Connect page does not have a sample about ODBC. Here you have some inspiration.
image
From the AIven Website I have got a file called ca.pem. Take a copy and pleace it in
C:\Users\Administrator\AppData\Roaming\postgresql
rename ca.pem to root.crt
Choose a database that exist, and press “Test”

In PowerShell do:
$query=‘select * from cities’
$conn = New-Object System.Data.Odbc.OdbcConnection
$conn.ConnectionString = “DSN=Aiven;DATABASE=de_tables”
$conn.open()
$cmd = New-object System.Data.Odbc.OdbcCommand($query,$conn)
$ds = New-Object system.Data.DataSet
$numrows = (New-Object system.Data.odbc.odbcDataAdapter($cmd)).fill($ds)
$conn.close()
foreach ($row in $ds.Tables[0].Rows ) {
write-host “$($row[1]) `t $($row.length)”
}
Write-host “Number of rows returned: $numrows”
$ds.tables[0].Rows | Out-GridView

As you can see, the name of the database in the ODBC setting can be overwrittes in PowerShell

1 Like

You’re correct to note that Quick Connect currently does not support ODBC so that you could use PowerShell. Could we ask you to suggest your idea here, so that we can research the use case and prioritize accordingly?

No, I have done my part. If you want to move the stuff around, then do it internally.
/T