ODBC Driver¶
The 3forge Enterprise ODBC driver lets Excel, pyodbc, and other ODBC tools on 64-bit Windows query 3forge Enterprise tables over the Center's JDBC listener.
Overview¶
The driver is a native Windows library built on the same client library as the C++ client. It connects to the Center's JDBC listener, port 3280 by default, and needs no Java. It is registered as forge ODBC Driver, with no leading "3", and that is the name to pick in ODBC tools.
Installing the driver¶
The installer, Install3ForgeODBCDriver-2.3.23.exe, installs the 64-bit driver and asks for administrator rights itself.
- Run
Install3ForgeODBCDriver-2.3.23.exeand accept the default directory,C:\Program Files\forge ODBC Driver, or choose another. - Open Start -> ODBC Data Sources (64-bit) and select the "Drivers" tab.
- Check that
forge ODBC Driveris listed.
The installer also:
- Installs the Visual C++ 2015-2022 x64 runtime if it is missing: it downloads the runtime from Microsoft, so an install on a machine without it needs internet access.
- Creates a data source named
forgeDSN: one for the current user and one for the machine, set tolocalhost, port3280, and the defaultdemologin. Reinstalling keeps the existing settings. - Creates
C:\ProgramData\3forge_odbc: the folder holds the driver's log, and every user on the machine has full control of it.
The installer adds no entry to the Windows list of installed apps. Its uninstaller is Uninstall3ForgeODBCDriver.exe, in the installation directory. It removes the driver, both forgeDSN data sources with any settings changed in them, and the log folder with its log.
Configuring the data source¶
A default install requires a client certificate on port 3280, so forgeDSN needs the certificate files before it can connect. See Creating a client certificate and Authorizing a client.
- Open Start -> ODBC Data Sources (64-bit), select the "System DSN" tab, select
forgeDSN, and select "Configure". -
Fill in the fields, then select "OK":
Field Default What it sets "Host" localhostThe server "Port" 3280The Center's JDBC listener "Username", "Password" demo,demo123The login "Use SSL" On TLS. Leave on for a default install "SSL Client Cert File" Empty Path to client.crt.pem"SSL Client Key File" Empty Path to client.key.pem"SSL Client Key Password" Empty The key's passphrase, if it is encrypted "SSL Server Pub File" Empty Path to the server's 3forge.pub. Without it, the driver accepts any server"Failover URLs" Empty Further servers, as host:port,host:port"Query Timeout (ms)" 60000The query timeout sent to the server "Rows Fetch Size" 10000The most rows one query returns. More rows are dropped without notice -
Confirm that a connection from Excel or
pyodbc, as below, returns rows.
The configuration dialog has no field for the data source's name. A data source added with "Add" on the "System DSN" or "User DSN" tab is named DSN.
Connecting from Excel¶
- In Excel, select Data -> Get Data -> From Other Sources -> From ODBC.
- Select
forgeDSN, then select "OK". - Check that the "Navigator" lists the instance's tables.
Connecting from code¶
Connect with a data source name, or with a connection string naming the driver:
Check that rows holds the rows of Quotes.
Pass autocommit=True: the driver supports autocommit only, and turning it off fails with HYC00 Transactions not supported.
A connection string can set every value directly:
| Keyword | Data source value | Default |
|---|---|---|
HOST |
Host |
localhost |
PORT |
Port |
3280 |
UID |
Username |
demo |
PWD |
Password |
demo123 |
SSL |
SSL |
On, unless set to 0 |
SSL_CLIENT_CERT_FILE |
SslClientCertFile |
Empty |
SSL_CLIENT_KEY_FILE |
SslClientKeyFile |
Empty |
SSL_CLIENT_KEY_PASSWORD |
SslClientKeyPassword |
Empty |
SSL_SERVER_PUB_FILE |
SslServerPubFile |
Empty |
FAILOVER_URLS |
FailoverUrls |
Empty |
AMI_QUERY_TIMEOUT_IN_MS |
QueryTimeoutMs |
60000 |
AMI_ROWS_FETCH_SIZE |
RowsFetchSize |
10000 |
The connection string takes the keywords in the first column; the data source stores the names in the second. A value cannot contain ;.
How the driver changes SQL¶
Before sending a statement, the driver rewrites it for 3forge Enterprise SQL:
- Single quotes become double quotes.
- In a
WHEREclause,=becomes==,LIKEbecomes~~, and%becomes*, including inside quoted text.
Results can differ from standard SQL:
LIKEmatches anywhere in the value:~~is a partial match, soLIKE 'M%'returns every value that containsM, such asIBMas well asMSFT.- A
%in a compared value is changed too:WHERE sym = '50%'compares against50*, so it does not find the value50%. >=,<=, and!=fail: the driver changes the=in each, and the server rejects the statement with009-EXCEPTION: Left side of declaration must be a variable. WriteNOT (n < 2)forn >= 2,NOT (n > 2)forn <= 2, andNOT (n = 2)forn != 2.
Logging¶
The driver logs to C:\ProgramData\3forge_odbc\3f_odbc_driver.log. The environment variable _3F_ODBC_LOG_LEVEL sets the level: debug, info, warn, or error. When it is not set, the level is debug. At info, the log leaves out the connection detail, including the missing-certificate message under When a connection fails.
The default log level records passwords
At the debug level the log records connection strings, including the password, and every user on the machine can read, change, and delete files in the log directory. Set _3F_ODBC_LOG_LEVEL to info on shared machines, and to debug only while diagnosing a connection.
When a connection fails¶
- Most connection failures report
HY000Failed to establish connection: a wrong host or port, a missing client certificate, a server key that does not match the pin file, and a connection withSSL=0to a TLS port look the same. - The connection waits for the login timeout: the application's login timeout, or 30 seconds when it sets none.
- A refused client certificate does not fail the connection: the connect succeeds, and each query then returns no result set and no error. An "SSL Server Pub File" path that does not exist does the same. Check that the first query returns rows.
- A wrong user name or password does not fail the connection: the first query fails with
HY000query failed: JDBC login refused by server: 005-AUTHENTICATION FAILED: BAD_CREDENTIALS.
At the debug level, the driver's log has more detail for a missing certificate: SSL is on but SSL_CLIENT_CERT_FILE/SSL_CLIENT_KEY_FILE is not set; ....
What this does not support¶
- Running in 32-bit applications or on other operating systems: the installer provides a 64-bit Windows driver only.
- Turning off autocommit: the driver supports no transactions.
- Binding date, time, or binary parameters: only input parameters of numeric, bit, and character types are accepted, and others are refused with
HYC00. - Telling connection failures apart by SQLSTATE: every connect failure is
HY000.