Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2012
    Posts
    2

    Unanswered: ODBC connection problem to DB2

    Hello,


    I'm having a problem in my application when I'm tring to connect to an DB2 ODBC driver using ODBC, I've imported the 4 files below:

    #include <windows.h>
    #include <sql.h>
    #include <sqlext.h>
    #include <sqltypes.h>

    First I used SQLConnect to connect to the ODBC driver which fine, however I discovered that I need to enable UNICODE in my app so I have set the UNICODE flag in the preprocessor definitions which calls SQLConnectW, my problem is that SQLConnectW fails to connect and returns -1.

    I have no idea what's wrong and why SQLConnect works and SQLConnectW doesn't...

    I'm running on windows.

    Your help is highly appreciated.

    DBL

  2. #2
    Join Date
    Oct 2009
    Location
    221B Baker St.
    Posts
    486
    Which release of db2 and fixpack is being used?

    What other diagnostic info (other then the -1) is presented?

  3. #3
    Join Date
    Aug 2012
    Posts
    2
    Hi,

    I first installed DB2 client on my Windows box, then I opened the ODBC Data Source Administrator and created a new user DSN using the IBM DB2 ODBC DRIVER version 9.07.01.462.

    Then I Called the connection function:

    char *dsnName = "DB2DNS";
    char* userID = "DB2USER";
    char* passwd = "DB2PASS";

    retcode = SQLConnect(hdlConn, (SQLCWHAR*)dsnName,SQL_NTS,(SQLWCHAR*)userID,SQL_N TS, (SQLWCHAR*)passwd, SQL_NTS);

    retcode RETURNS -1, hdlConn was allocated sucessfully, any idea was am I doing wrong?

    Thanks.

  4. #4
    Join Date
    Apr 2012
    Posts
    1,034
    Provided Answers: 18
    From odbcad32, can you successfully connect to the db2 database with those credentials?

    If you can connect successfully there, you might have made a programming error.
    If that is the case, please follow the sample code provided by IBM .
    The file(s) containing the sample code live on the DB2 server in the directory SQLLIB / samples/ cli.
    The samples are also available on-line at
    CLI samples - IBM DB2 9.7 for Linux, UNIX, and Windows

  5. #5
    Join Date
    Aug 2012
    Posts
    45
    [QUOTE=DB-layer;6564140]then I opened the ODBC Data Source Administrator and created a new user DSN using the IBM DB2 ODBC DRIVER version 9.07.01.462.[QUOTE]

    DB-layer, I don't know much about DB2, but for us a DSN created with the windows data source administrator does not connect. The only way we could connect is by creating the DSN with DB2 Connect configuration assistant. I feel the windows application *should* work, and maybe there is a way to do it, but were not successful with it.

    Greg

  6. #6
    Join Date
    Apr 2012
    Posts
    1,034
    Provided Answers: 18
    Always create your DB2 data sources with DB2 tools only (e.g either via scripted command-line commands, or via a GUI like db2ca or equivalent).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •