Query fails with C++ ODBC - works with Management Studio
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Query fails with C++ ODBC - works with Management Studio

  1. #1
    Join Date
    Aug 2002
    Posts
    640

    Query fails with C++ ODBC - works with Management Studio

    Hi, ALL,

    I'm trying to execute a following query (using MSBV 2010, ODBC, SQL Server 2008):
    Code:
    L"SELECT rtrim(abt_tnam), abt_tid, rtrim(abt_ownr), abd_fhgt, abd_fwgt, abd_fitl, abd_funl, abd_fchr, abd_fptc, rtrim(abd_ffce), abh_fhgt, abh_fwgt, abh_fitl, abh_funl, abh_fchr, abh_fptc, rtrim(abh_ffce), abl_fhgt, abl_fwgt, abl_fitl, abl_funl, abl_fchr, abl_fptc, rtrim(abl_ffce), rtrim(abt_cmnt) FROM abcattbl WHERE \"abt_tnam\" = ? AND \"abt_ownr\" = ?;";
    When executed inside SQL Server Management Studio there is no issue. The query is executing fine and I am getting the results.

    However when executing thru the C++ code, the call to SQLExecute() fails. The error is:
    String data, right truncation
    and the error code is 22001.

    If I Remove rtrim() calls, everything works fine. Unfortunately this is not an option as those fields are char() and not varchar().

    Moreover this same query works fine on PostgreSQL driver on OSX with iODBC DM.

    Trying to wrap the parameters with rtrim() also doesn't help. I'm getting exactly the same error.

    Below is the table structure:
    Code:
    CREATE TABLE \"abcattbl\"(abt_tnam char(129) NOT NULL, abt_tid integer, abt_ownr char(129) NOT NULL, abd_fhgt smallint, abd_fwgt smallint, abd_fitl char(1), abd_funl char(1), abd_fchr smallint, abd_fptc smallint, abd_ffce char(18), abh_fhgt smallint, abh_fwgt smallint, abh_fitl char(1), abh_funl char(1), abh_fchr smallint, abh_fptc smallint, abh_ffce char(18), abl_fhgt smallint, abl_fwgt smallint, abl_fitl char(1), abl_funl char(1), abl_fchr smallint, abl_fptc smallint, abl_ffce char(18), abt_cmnt char(254) PRIMARY KEY( abt_tnam, abt_ownr ));
    Does anybody have an idea what is going on and how do I fix this?

    TIA!

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    19,012

    Re: Query fails with C++ ODBC - works with Management Studio

    Did you search the google for this error?
    Could this help?
    Victor Nijegorodov

  3. #3
    Join Date
    Aug 2002
    Posts
    640

    Re: Query fails with C++ ODBC - works with Management Studio

    Hi, VictorN,
    Quote Originally Posted by VictorN View Post
    Did you search the google for this error?
    Could this help?
    Yes, I did search, but didn't see that link.
    I will try to call the function referenced and hopefully it will be fixed.

    Thx.

  4. #4
    Join Date
    Aug 2002
    Posts
    640

    Re: Query fails with C++ ODBC - works with Management Studio

    VictorN,
    Adding the function from the link you referenced solved it.

    Thx.

    P.S.: Sorry, I didn't get this in my google search.

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    19,012

    Re: Query fails with C++ ODBC - works with Management Studio

    You are welcome!
    Victor Nijegorodov

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)