blog
blog copied to clipboard
IBM i ODBC for Windows DSN
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.
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).
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).
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).
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();
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 https://worksofbarry.com/ghpost.html?25
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)