mysql - SQLConnect Fails With Data source name not found, and no default driver specified C++ -


i have installed unixodbc , having ubuntu 14. below

#cat /etc/odbc.ini  [mariadb] description     = odbc mariadb  driver              = /usr/lib/x86_64-linux-gnu/libmaodbc.so setup               = /usr/lib/x86_64-linux-gnu/odbc/libodbcmys.so usagecount      = 1 

and

# cat /etc/odbcinst.ini  [mariadb] description     = odbc mariadb  driver              = /usr/lib/x86_64-linux-gnu/libmaodbc.so setup               = /usr/lib/x86_64-linux-gnu/odbc/libodbcmys.so usagecount      = 1  // sqlconnect_ref.cpp // compile with: odbc32.lib #include <sqlext.h> #include <mysql/mysql.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <string>  using namespace std;  void extract_error(char *fn, sqlhandle handle, sqlsmallint type) {     sqlinteger = 0;     sqlinteger nativeerror;     sqlchar sqlstate[ 7 ];     sqlchar messagetext[256];     sqlsmallint textlength;     sqlreturn ret;      std::cout << "\nthe driver reported following error \n" << fn;         {         ret = sqlgetdiagrec(type, handle, ++i, sqlstate, &nativeerror,                         messagetext, sizeof(messagetext), &textlength);         if (sql_succeeded(ret)) { //            std::cout << "%s:%ld:%ld:%s\n" << sqlstate << (long) <<          (long) nativeerror << messagetext;          std::cout << sqlstate << (long) << (long) nativeerror << messagetext<<std::endl;         } } while( ret == sql_success ); }   #define check_error(e, s, h, t) ({\         if (e!=sql_success && e != sql_success_with_info)       {extract_error(s, h, t); return 1;} \ })  int main() {    sqlhenv henv;    sqlhdbc hdbc;    sqlhstmt hstmt;    sqlreturn retcode;    sqlchar * outconnstr = (sqlchar * )malloc(255);   sqlsmallint * outconnstrlen = (sqlsmallint *)malloc(255);    // allocate environment handle   retcode = sqlallochandle(sql_handle_env, sql_null_handle, &henv);    // set odbc version environment attribute   if (retcode == sql_success || retcode == sql_success_with_info) {   retcode = sqlsetenvattr(henv, sql_attr_odbc_version,      (void*)sql_ov_odbc3, 0);    // allocate connection handle       if (retcode == sql_success || retcode == sql_success_with_info) {      retcode = sqlallochandle(sql_handle_dbc, henv, &hdbc);       // set login timeout 5 seconds      if (retcode == sql_success || retcode == sql_success_with_info) {         sqlsetconnectattr(hdbc, sql_login_timeout, (sqlpointer)5, 0);           // connect data source        // retcode = sqlconnect(hdbc, connstr, sql_nts, (sqlchar*) null, 0, null, 0);     retcode = sqlconnect( hdbc,             (sqlchar*) "mydb", sql_nts,             (sqlchar*) "", sql_nts,             (sqlchar*) "", sql_nts );         check_error(retcode, (char *)"sqlconnect", hdbc, sql_handle_dbc);          // allocate statement handle         if (retcode == sql_success || retcode == sql_success_with_info) {            retcode = sqlallochandle(sql_handle_stmt, hdbc, &hstmt);             // process data            if (retcode == sql_success || retcode == sql_success_with_info) {              std::ostringstream createtablednstr;             createtablednstr << "create table mytable\n"             << "(\n"             << "    myid    integer    auto_increment primary key,\n"             << "    dummy   integer    not null\n"             << ")"             << "    engine = myisam\n";              retcode = sqlprepare(hstmt, (sqlchar *)createtablednstr.str().c_str(),sql_nts);             if (retcode != sql_success)             {                            std::cout << "sqlprepare retcode != sql_success";              }             retcode = sqlexecute(hstmt);             if (retcode != sql_success)             {                  std::cout << "sqlexecute retcode != sql_success";              }                sqlfreehandle(sql_handle_stmt, hstmt);            }            else { std::cout << "sqlallochandle error" << std::endl; }             sqldisconnect(hdbc);         }         else { std::cout << "sqlconnect error" << std::endl; }          sqlfreehandle(sql_handle_dbc, hdbc);      }   }   sqlfreehandle(sql_handle_env, henv);    } } 

i compiled

g++ odbc.cpp -l odbc

when run driver reported following error

sqlconnectim00210[unixodbc][driver manager]data source name not found,       , no default driver specified 

is have right configuration in .ini files or missing .

can please guide same ?

thanks in advance.

  sdk 


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -