blog icon indicating copy to clipboard operation
blog copied to clipboard

IBM i ODBC for Windows DSN

Open worksofliam opened this issue 5 years ago • 3 comments

After you have the IBM i Access ODBC Driver installed for Windows, you can set up a DSN (data source name) which can point to a specific connection. The reason you would setup a DSN is you don't have to adjust the connection string for each different system or user your application runs under.


If you launch the ODBC Data Source Administrator, go to the System DSN tab and hit the 'Add' button. This will launch a new Window where you can select the IBM i Access ODBC Driver and then hit finish.

image

This will launch a new window where you can enter the DSN alias name (the source name) and the remote system hostname or address (in the System box).

image

By clicking the Connection Options you can then further enter a username for the connection and also tell it what type of connection to use (SSL vs non-SSL for example).

image

As an additional extra, if you head over to the server tab you can change the SQL naming type, set the default schema/library and set the library list (but this only works when using *SYS/system naming).

image


Now in our connection string, you only have to provide a DSN and a password. Note; you only have to provide a password unless you have an SSH key setup within ACS. See how we are not providing a schema/library in our statement? That is because we change the default schema in the DSN settings.

const odbc = require('odbc');
​
async function example() {​
    const connection = await odbc.connect(`DSN=DEVSERV;Password=mypassword`);​
    const result = await connection.query('SELECT * FROM QCUSTCDT');​
    console.log(result);​
}​
​
example();

worksofliam avatar Jul 09 '19 13:07 worksofliam

Hi Liam, How to install IBM i Access ODBC Driver in windows. If I install Client Access for iSeries it comes automatically but If I do not have it, then is there a way to install separately? Thanks in advance!

yusy4code avatar Nov 29 '19 08:11 yusy4code

@yusy4code https://worksofbarry.com/ghpost.html?25

jsoques avatar Feb 16 '20 12:02 jsoques

Do you know of an easy way to distribute a DSN connection with an application?

I recently wrote a Go app (using "github.com/alexbrainman/odbc")

I needed to distribute to multiple PC's and didn't want to have the users set up an ODBC conenction on every machine (read I didn't want to have to set-up an ODBC connection on every users machine!), the best way I found to to do it was a DSN-less connection in app.

I stored the connection properties in a JSON file, then built up a DSN connection string in the app

The only prerequisite was that the ODBC driver was installed on the PC (as I had hardcoded the Driver name)

priceaj avatar Feb 17 '20 12:02 priceaj