Assistance in troubleshooting connecting to Vertica via odbc from a cpp application


I'm building an application in cpp that should connect to a vertica database. 

I've installed the odbc driver on the dev machine and defined a DSN named "Vertica". it works fine via isql, but the following code results in  "Could not connect to database":


    const char* dsnName = "Vertica";
const char* userID = "<omitted>";
const char* passwd = "<omitted>";
ret = SQLConnect(hdlDbc, (SQLCHAR*)dsnName,SQL_NTS,(SQLCHAR*)userID,SQL_NTS,(SQLCHAR*)passwd, SQL_NTS);
if(!SQL_SUCCEEDED(ret)) {
printf("Could not connect to database.\n");

Upon debug, the ret variable is found to be -1. 

Is there any way to get a more verbose response? 



  • Options

    Hi Tomer,


    Since you're using isql to test the DSN, I assume your client code is on Linux? Have you conifgured a vertica.ini file?  You can add logging settings in the vertica.ini file to get a better idea of what is happening when you client attempts to connect. Please see Additional Parameter Settings in the documentation.




  • Options

    I've setup the odbc.ini, odbcinst.ini and vertica.ini files as per the instructions and set an environment variable VERTICAINI. I found out how to catch the error message (good idea to add it to the connection instructions BTW...). 
    When invoking the following code:

        ret = SQLConnect(hdlDbc, (SQLCHAR*)dsn, sizeof(dsn)-1,(SQLCHAR*)userID,sizeof(userID)-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 = "*********************************"
    Description = HP Vertica DSN ODBC driver for ****
    Driver = /opt/vertica/lib64/libverticaodbc.so
    Database = ****
    Servername = ***********************.hp.com
    UserName = ******
    Password = *******
    Port = ****



    This is vertica.ini:

    r$ cat /etc/vertica.ini


  • Options

    Ok, thanks to vertica-forums I found the problem. I was linking to libverticaodbc and I should've been lining to libodbc.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file