Menu

SQLConnectW Failed

Help
zzr
2011-04-18
2013-04-15
  • zzr

    zzr - 2011-04-18

    When I use SQLConnect, it is OK. And I can get data from the database.
    But when I use the code below

    #define SQL_WCHART_CONVERT
    #define UNICODE
    #include <sqlext.h>
    #include <sqlucode.h>

    SQLConnectW(hdbc,
    (SQLTCHAR*)(L"mytest"), SQL_NTS,
    (SQLTCHAR*)(L"sa"), SQL_NTS,
    (SQLTCHAR*)(L"aaa999"), SQL_NTS);

    The return code is -1.Why?

    My environment:
    fedora core 14
    gcc 4.5.1
    unixODBC 2.3.0
    sql server 2000 sp4
    freetds

    thanks!

     
  • Nick Gorham

    Nick Gorham - 2011-04-18

    Hi,

    What error message do you get back from the SQLConnectW?

    using 4 byte unicode is always going to cause problems. The DM will convert to single bytes if the driver doesn't expose the W functions. But if it does, it will pass the 4 byte unicode on as it is, so you need to ensure that the driver also understands 4 byte unicode.

     
  • zzr

    zzr - 2011-04-19

    The error message is unreadable code
    So I have to use

    SQLTCHAR buf = {0};
    SQLGetDiagRec( SQL_HANDLE_DBC, hdbc, 1,
    odstat, &oderr, buf, SQL_MAX_MESSAGE_LENGTH, &len );
    char* p = (char*)buf;
    for (int i = 0; i < len; ++i)
    {
            cout << p;
            p += 2;
    }
    cout << endl;

    Then I get the next message:
    Data source name not found, and no default driver specified

    Is this mean the driver can not support?

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.