ODBC with Visual BasicΒΆ
About
Use ADODB to access data from your Visual Basic applications.
Install
The PostgreSQL ODBC driver can be used to connect to CrateDB from ODBC environments.
Install and configure the PostgreSQL ODBC driver
While Windows typically includes an ODBC driver manager, you can install the unixODBC driver manager on Linux and macOS systems. The PostgreSQL ODBC driver is called psqlODBC.
Please navigate to the psqlODBC download site to download and install the latest psqlODBC driver for Windows systems. Installing PostgreSQL ODBC drivers on Windows includes an illustrated walkthrough.
On Linux, install the unixODBC ODBC driver manager and the psqlODBC driver. Installing PostgreSQL ODBC drivers on Linux includes an illustrated walkthrough.
Arch Linux
pacman -Sy psqlodbc
Debian and derivatives
apt install --yes odbc-postgresql odbcinst unixodbc
Red Hat and derivatives
yum install -y postgresql-odbc
Verify installation.
odbcinst -q -d
[PostgreSQL ANSI]
[PostgreSQL Unicode]
On macOS, install the unixODBC ODBC driver manager and the psqlODBC driver, then register it.
# macOS
brew install psqlodbc unixodbc
odbcinst.ini
[PostgreSQL Unicode]
Description = PostgreSQL ODBC driver (Unicode version)
Driver = /usr/local/lib/psqlodbcw.so
odbcinst -i -d -f odbcinst.ini
Verify installation.
odbcinst -q -d
[PostgreSQL Unicode]
Synopsis
example.vb
Dim cn as New ADODB.Connection
Dim rs as New ADODB.Recordset
'Connect to database
cn.Open "Dsn=<MyDataSourceName>;" & _
"Server=localhost;" & _
"Port=5432;" & _
"Uid=crate;" & _
"Pwd=crate;" & _
"MaxVarcharSize=1073741824;"
'Invoke query
rs.Open "SELECT * FROM sys.summits ORDER BY height DESC LIMIT 5", cn
'Display results
While Not rs.EOF
Debug.Print rs!mountain & ": " & rs!height
rs.MoveNext
Wend
'Clean up
rs.Close
cn.Close
See also
Example: psqlODBC with Visual Basic.