Error connection to vertica from cpp application

Moderator: NorbertKrupa

Post Reply
tomersagi
Newbie
Newbie
Posts: 5
Joined: Wed Apr 15, 2015 9:14 am

Error connection to vertica from cpp application

Post by tomersagi » Wed Apr 15, 2015 9:29 am

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

User avatar
JimKnicely
Site Admin
Site Admin
Posts: 1825
Joined: Sat Jan 21, 2012 4:58 am
Contact:

Re: Error connection to vertica from cpp application

Post by JimKnicely » Wed Apr 15, 2015 1:57 pm

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!
Jim Knicely

Image

Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.

tomersagi
Newbie
Newbie
Posts: 5
Joined: Wed Apr 15, 2015 9:14 am

Re: Error connection to vertica from cpp application

Post by tomersagi » Thu Apr 16, 2015 7:51 am

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

id10t
GURU
GURU
Posts: 732
Joined: Mon Apr 16, 2012 2:44 pm

Re: Error connection to vertica from cpp application

Post by id10t » Thu Apr 16, 2015 8:09 am

Hi!

[DELETED]
Last edited by id10t on Thu Apr 16, 2015 12:10 pm, edited 1 time in total.

tomersagi
Newbie
Newbie
Posts: 5
Joined: Wed Apr 15, 2015 9:14 am

Re: Error connection to vertica from cpp application

Post by tomersagi » Thu Apr 16, 2015 11:09 am

Looking at your suggestion I found my problem.
I linked with libverticaodbc and not libodbc.
Thanks for the tip
Tomer

User avatar
JimKnicely
Site Admin
Site Admin
Posts: 1825
Joined: Sat Jan 21, 2012 4:58 am
Contact:

Re: Error connection to vertica from cpp application

Post by JimKnicely » Thu Apr 16, 2015 12:09 pm

#id10t - Nice! :D
Jim Knicely

Image

Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.

gray
Newbie
Newbie
Posts: 1
Joined: Wed Dec 23, 2015 1:34 pm

Re: Error connection to vertica from cpp application

Post by gray » Wed Dec 23, 2015 1:47 pm

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.

Post Reply

Return to “ODBC”