Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

Hi, I have installed sql anywhere 16 in linux machine. Below is the content of my odbc.ini file. I have written the odbc program to access the demo database(which came as part of sql anywhere16 installation). While running the program am getting the error message - "NOTICE: IM004:1:0:[unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed".

[SQL Anywhere 16 Demo]
Port                = 2638
Description=SQL Anywhere 16 Sample Database

Can anyone help me to identify the problem with my settings?

Thanks, Vaish

asked 19 Nov '13, 00:00

Vaish's gravatar image

accept rate: 0%

edited 19 Nov '13, 03:22

Mark%20Culp's gravatar image

Mark Culp

Can you show us your code? Which call is getting the error? Which build number (of the ODBC driver) are you using? What bitness are you using - 32 or 64?

(19 Nov '13, 03:24) Mark Culp

;; This buffer is for notes you don't want to save, and for Lisp evaluation. ;; If you want to create a file, visit that file with C-x C-f, ;; then enter the text in that file's own buffer.

Hi , My code is below:

static void
odbcGetTableSize(char *svr_dsn, char *svr_database, char *svr_schema, char *svr_table,
                 char *username, char *password, char *sql_count, unsigned int *size)
    SQLHENV env;
    SQLHDBC dbc;
    SQLHSTMT stmt;
    SQLRETURN ret;

StringInfoData      conn_str;
    StringInfoData      sql_str;
    SQLCHAR OutConnStr[1024];
    SQLSMALLINT OutConnStrLen;

SQLUBIGINT table_size;
    SQLLEN indicator;

StringInfoData name_qualifier_char;
    StringInfoData quote_char;

/* Construct connection string */
    if (svr_database != NULL)
        appendStringInfo(&conn_str, "DSN=%s;DATABASE=%s;UID=%s;PWD=%s;", svr_dsn, svr_database, username, password);
        appendStringInfo(&conn_str, "DSN=%s;UID=%s;PWD=%s;", svr_dsn, username, password);
#ifdef DEBUG
    elog(DEBUG4, "odbc_fdw::odbcGetTableSize: Connection string: %s",;
    /* Allocate an environment handle */
    /* We want ODBC 3 support */
    SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
    /* Allocate a connection handle */
    SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc);

/* Connect to the DSN */
    ret = SQLDriverConnect(dbc, NULL, (SQLCHAR *), SQL_NTS,
                           OutConnStr, 1024, &OutConnStrLen, SQL_DRIVER_COMPLETE);


It fails in - SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env); Am working on 32 bit. And the ODBC driver is the one which came along with sqlanywhere16 installation . My Linux distro is - Red Hat Enterprise Linux Server release 5 (Tikanga).

Also, If you could tell me the procedure to run the sample programs given in path - sdk/dbcapi/examples/ in linux, it would be very helpful. My attempt to compilation with this command - gcc -I/home/vaish/sqlanywhere16/sdk/include/ -I/usr/include/ -L/usr/local/lib/ -L/usr/lib/ connecting.cpp -o connecting

failed with below errors:

/tmp/ccXZBXeJ.o: In function `main':
connecting.cpp:(.text+0x26): undefined reference to `sqlany_initialize_interface(SQLAnywhereInterface*, char const*)'
connecting.cpp:(.text+0x8f): undefined reference to `sqlany_finalize_interface(SQLAnywhereInterface*)'
connecting.cpp:(.text+0x142): undefined reference to `sqlany_finalize_interface(SQLAnywhereInterface*)'
/tmp/ccXZBXeJ.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

Thanks , Vaish

(19 Nov '13, 18:01) Vaish
Comment Text Removed

Hi, Basically I need to connect to sybase database in Linux via C programming in linux. I searched on the net and found only tutorial for programming in windows environment/C++ programming. So , If there is any good documentation on connecting sybase in linux C programming , plz share me the link. It will be of great help. Thanks, Vaish

(19 Nov '13, 20:42) Vaish

ODBC connection failures

If you do not deploy all the files required for the ODBC driver, you may encounter the following error when attempting to connect to a database.

[IM004][Microsoft][ODBC Driver Manager] Driver's SQLAllocHandle on SQL_HANDLE_ENV failed

Check that you have installed all the files required for the correct operation of the ODBC driver.

permanent link

answered 19 Nov '13, 11:37

JBSchueler's gravatar image

accept rate: 20%

PS. I recently added this to the SQL Anywhere documentation. You'll see it in some new release.

(19 Nov '13, 11:39) JBSchueler
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 19 Nov '13, 00:00

question was seen: 11,508 times

last updated: 19 Nov '13, 21:52