Page 1 of 1

Error connection to vertica from cpp application

Posted: Wed Apr 15, 2015 9:29 am
by tomersagi
Hi,
I'm writing a cpp application that connects to a vertica 7.1 server via odbc. The development system is an hLinux (Debian variant), I'm using the latest odbc driver manager and drivers from vertica.
I've setup the odbc.ini, odbcinst.ini and vertica.ini files as per the instructions and set an environment variable VERTICAINI. I'm able to connect to the server using "isql <myDSNName>".
But, when invoking the following code:

Code: Select all

    ret = SQLConnect(hdlDbc, (SQLCHAR*)dsn, sizeof(dsn)-1,(SQLCHAR*)userID,sizeof(userID)-1,
                     (SQLCHAR*)passwd,sizeof(passwd)-1);
    if(!SQL_SUCCEEDED(ret)) {
        SQLCHAR *sqlstate = new u_char[6];
        SQLINTEGER nativeError=0;

        SQLCHAR *messageText = new u_char[255];
        SQLSMALLINT textLength =0;
        SQLGetDiagRec(SQL_HANDLE_DBC,hdlDbc,1, sqlstate,
                      &nativeError, messageText,
                      255, &textLength);
        printf("Could not connect to database.\n");
        cout << messageText << endl;
    }
This is the driver response:
Could not connect to database.
[Vertica][ODBC] (10380) Unable to establish a connection with data source. Missing settings: {[Database] [ServerName]}
I've checked the odbc.ini file and these two properties appear (stars mask the actual values for security reasons):

$ cat /etc/odbc.ini
[ODBC Data Sources]
Vertica = "*********************************"
[Vertica]
Description = HP Vertica DSN ODBC driver for ****
Driver = /opt/vertica/lib64/libverticaodbc.so
Database = ****
Servername = ***********************.hp.com
UserName = ******
Password = *******
Port = ****
LogLevel=4
LogPath=/tmp

Ideas anyone?
Thanks,
Tomer

Re: Error connection to vertica from cpp application

Posted: Wed Apr 15, 2015 1:57 pm
by JimKnicely
Hi,

Can you show in your code where you set the dsn variable?

Also, the Vertica examples all use the SQL_NTS macro to specify a NULL terminated string...

Code: Select all

ret = SQLConnect(hdlDbc, (SQLCHAR*)dsn,
    SQL_NTS,(SQLCHAR*)userID,SQL_NTS,
    (SQLCHAR*)passwd, SQL_NTS);
Thanks!

Re: Error connection to vertica from cpp application

Posted: Thu Apr 16, 2015 7:51 am
by tomersagi
Thanks for answering,
This is where dsn is defined:

Code: Select all

class DBA
{
public:
	
        DBA();
        ~DBA();
        const char *dsn = "Vertica";
And I tried with SQL_NTS beforehand, changed to sizeof in a desperate attempt to figure out the problem.
Anyway, rerunning with SQL_NTS gives the same result.
Tomer

Re: Error connection to vertica from cpp application

Posted: Thu Apr 16, 2015 8:09 am
by id10t
Hi!

[DELETED]

Re: Error connection to vertica from cpp application

Posted: Thu Apr 16, 2015 11:09 am
by tomersagi
Looking at your suggestion I found my problem.
I linked with libverticaodbc and not libodbc.
Thanks for the tip
Tomer

Re: Error connection to vertica from cpp application

Posted: Thu Apr 16, 2015 12:09 pm
by JimKnicely
#id10t - Nice! :D

Re: Error connection to vertica from cpp application

Posted: Wed Dec 23, 2015 1:47 pm
by gray
I spent a hour to solve the same problem on OS X :evil:
I saw the same error:

Code: Select all

[08001][unixODBC][Vertica][ODBC] (10380) Unable to establish a connection with data source. Missing settings: {[Database] [ServerName]}
In my case, solution is:

Code: Select all

export VERTICAINI=/Library/Vertica/ODBC/lib/vertica.ini
export ODBCINI=/usr/local/etc/odbc.ini
Be careful! Vertica Client Drivers software creates files during an installation /etc/odbc.ini and /etc/odbcinst.ini. unixODBC works with files in directory /usr/local/etc. You should move them to this dir.
Hope I saved someone's time.