Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2013
    Posts
    6

    Unanswered: SQLExecute( ) Fails with SQLSTATE=42601

    I am trying to learn ODBC/CLI Programming so please bear with me if this appears silly, but I am not able to resolve an apparently simple issue. I have posted the relevant portions of the code below.

    The problem is that the SQLExecute () fails with SQLSTATE=42601. The exact error message that I get is "0x00167250 "[IBM][CLI Driver][DB2/NT] SQL0007N The character " " following "ΜΜΜΜΜΜ©%|I0ύ" is not valid. SQLSTATE=42601"

    Can someone please help me point out issues / ways to debug this Issue on MS Visual Studio 2012 (Express). (DB2 Express C Version 10.1.2)

    I have checked the manuals and the SQLSTATE refers to an invalid character in the Query String. As far as I understand, there isn't any! Nor am I able to figure it out from the Error message produced. Please help!

    Regards,


    /* Define a SELECT SQL Statement That uses a Paramter
    Marker. !! Protect from Buffer Overflow !! */

    strcpy((char *) sqlQuery, "SELECT EMPNO, LASTNAME FROM ");
    strcat((char *) sqlQuery, "EMPLOYEE WHERE JOB = ?");

    /*Prepare the SQL Statement */
    sqlReturnCode = SQLPrepare(*StmtHandle,
    (SQLCHAR*) sqlQuery,
    SQL_NTS);

    if (sqlReturnCode != SQL_SUCCESS){
    //Free Connection Handle
    //Free Environment Handle
    GetCLIErrorInfo(SQL_HANDLE_STMT, *StmtHandle);
    return -60;
    }

    sqlReturnCode = SQLBindParameter(*StmtHandle,
    1,
    SQL_PARAM_INPUT,
    SQL_C_CHAR,
    SQL_CHAR,
    sizeof(jobType),
    0,
    jobType,
    sizeof(jobType),
    NULL);

    if (sqlReturnCode != SQL_SUCCESS){
    GetCLIErrorInfo(SQL_HANDLE_STMT, *StmtHandle);
    return -70;
    }

    /*Populate the Bound Application Variable*/
    strcpy((char*) jobType, "DESIGNER");

    /*Execute the SQL Statement*/
    sqlReturnCode = SQLExecute(*StmtHandle);

    if (sqlReturnCode != SQL_SUCCESS){
    //Free Connection Handle
    //Free Environment Handle
    GetCLIErrorInfo(SQL_HANDLE_STMT, *StmtHandle);
    return -80;
    }

  2. #2
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    you could activate the trace from db2cli.ini and see what is transmitted to the db/query
    Tracing the CLI driver by using the db2cli.ini file - IBM DB2 9.7 for Linux, UNIX, and Windows
    Best Regards, Guy Przytula
    Database Software Consultant
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

  3. #3
    Join Date
    Jan 2013
    Posts
    6
    Hi,

    Thanks for the reply! I did what you stated and I have a trace log as well however, I don't see any SQL query in the log file! Could you please have a look and suggest where I am going wrong?

    I have attached the source file and trace log. Please have a look.

    Code : http://codepad.org/ap8JCSgL
    Trace : http://codepad.org/grxhMf3P

    Regards

    [Edit]

    Hi,

    I'm sorry I am editing my earlier reply, but I'm not sure if this is appropriate. I have managed to figure out the Issue I guess. I had compiled the code and used "Unicode Character Set" which resulted in an invalid string being passed to SQLPrepare ( ) . (Not sure how it returned a successful completion code though!)

    I compiled the code again, and this time used "Multi-Byte Character Set". I can finally see the SQL query in the trace log and the error that I get is "[IBM][CLI Driver][DB2/NT] SQL0204N "DB2ADMIN.EMPLOYEE" is an undefined name. SQLSTATE=42704" and it looks like an access Issue.

    Pardon me, but I have never worked with a relational database before. I know this is something silly but please help!

    New Trace Log : http://codepad.org/ylQIfWDt

    [/Edit]
    Attached Files Attached Files
    Last edited by BumbleI3ee; 01-23-13 at 14:09.

  4. #4
    Join Date
    Jan 2013
    Posts
    6
    @ Guy

    Thanks for the help. The trace clinched it! I have managed to setup the Right Schemas, granted appropriate privileges to the user ID and I've been able to fetch a record from the table. Much appreciated. Thanks!

Posting Permissions

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