Question

I am trying to use odbc to connect to monetDB in node.js. However, I keep getting the following error:

The driver reported the following diagnostics whilst running SQLDriverConnect

IM002:1:0:[unixODBC][Driver Manager]Data source name not found, and no default driver      specified
DEBUG: []

Here is the source code:

var sys  = require("util");
var odbc = require("/home/vash/node_modules/odbc/odbc.js");

var db = new odbc.Database();
db.open("Driver={ODBC for MonetDB};Setup=/usr/lib/libMonetODBCs.so;UsageCount= 1;SERVER=vash-G75VW;USER=monetdb;PASSWORD=monetdb;PORT=5000;DATABASE=demo", function(err)
{
    db.query("select * from demo", function(err, rows, moreResultSets)
    {
        sys.debug(sys.inspect(rows));
        db.close(function(){});
    });
});

Using the command "isql -v monetdb", I can connect to monetDB using ODBC with the following odbc.ini and odbcinst.ini contents:

[monetdb]
Description             = "ODBC for MonetDB"
Driver          = /usr/lib/libMonetODBC.so
Setup           = /usr/lib/libMonetODBCs.so
UsageCount              = 1
SERVER = vash-G75VW
USER = monetdb
PASSWORD = monetdb
PORT = 5000 
DATABASE = demo

Since I connect using isql, I am guessing the problem lies in the line of code:

"Driver={ODBC for MonetDB};Setup=/usr/lib/libMonetODBCs.so;UsageCount= 1;SERVER=vash-G75VW;USER=monetdb;PASSWORD=monetdb;PORT=5000;DATABASE=demo"

Any ideas what's wrong, and do I have the connection string above set properly?

Was it helpful?

Solution

First thing is you are mixing up your odbc.ini and odbcinst.ini settings (although you're getting away with it in part). The odbcinist.ini file contains a list of drivers where each driver is named in [] and what follows are the driver attributes. So if the contents of your odbcinst.ini file is as you show above you've named a driver called "monetdb" which has various attributes. The only attribute you absolutely need for a driver is the driver attribute and it should point to the shared object for your driver. The additional attributes usagecount, description and setup are optional. The description can be returned from some ODBC APIs and the setup library tells the driver manager which setup library to load if it is required (which on unix it rarely is) (say if the driver wanted to prompt for a password or you gave it insufficient attributes to connect). So your odbcinst.ini file should look like this (Note, I've deliberately renamed your driver key to make things obvious):

[monetdb_driver]
Description             = "ODBC Driver for MonetDB"
Driver          = /usr/lib/libMonetODBC.so
Setup           = /usr/lib/libMonetODBCs.so
UsageCount              = 1

The /etc/odbc.ini file contains SYSTEM DSNs and is created like the odbcinst.ini file except each entry in [] is a DSN name. The only attribute a DSN absolutely needs is the Driver attribute as it names the ODBC driver to use for this DSN. The driver named should be a key in the odbcinst.ini file so for you your odbc.ini file should look like this (baring in mind I renamed your driver again):

[monetdb]
Description             = "DSN for MonetDB"
Driver          = monetdb_driver
SERVER = vash-G75VW
USER = monetdb
PASSWORD = monetdb
PORT = 5000 
DATABASE = demo

Bare in mind you can have USER DSNs to and they generally go in ~/.odbc.ini (see the output of odbcinst -j below).

You will find unixODBC's odbcinst command useful too as you can run it to check where your ini files should be:

$odbcinst -j
unixODBC 2.2.14
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /home/martin/.odbc.ini
SQLULEN Size.......: 4
SQLLEN Size........: 4
SQLSETPOSIROW Size.: 2

Once you've done this your isql command (as before) should work - something like:

isql -v monetdb your_username your_password

Now for your call to SQLDriverConnect.

db.open("Driver={monetdb_driver};SERVER=vash-G75VW;USER=monetdb;PASSWORD=monetdb;PORT=5000;DATABASE=demo",

I don't use monetdb so I cannot be sure about the attributes other than the "Driver" one but ODBC generally uses the attributes UID and PWD for username and password. I can believe monetdb has a port and database attribute.

You can find out a lot more about ODBC on unix and who the connection process works from Linux/UNIX ODBC and ODBC - The Connection Process both of which I wrote.

If you are only going to connect using a DSN-less connection string (which your call to SQLDriverConnect is above) you can now delete the contents of the odbc.ini file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top