0

I am writing function to call stored procedure in Oracle. When trying to call SQLConnectA, it fails, and SQLGetDiagRec returns some weird numbers, which looks like memory address instead of diagnostic message. Code which produced this error is

    ret = SQLConnectA(hORAdbc, (SQLCHAR*)DCDSN.c_str(), DCDSN.length(), (SQLCHAR*)DCUSR.c_str(), DCUSR.length(), (SQLCHAR*)DCPWD.c_str(), DCPWD.length());
if (ret != SQL_SUCCESS) {

    rc = SQLGetDiagRec(SQL_HANDLE_DBC, hORAdbc, 1, SqlState, &NativeError, Msg, sizeof(Msg), &MsgLen);
    appfile << "MAIN:SQLConnectA hORAdbc> SQLSTATE: " << SqlState << " NativeError: " << NativeError << " Msg: " << Msg << endl;

    return 0;
}

note: appfile is ofstream object (text file used for logging)

Where is the cause of this behaviour ?

Jan Bohac
  • 69
  • 7

1 Answers1

0

Msg returns pointer array of chars, so if you output it directly it just writes the address of the first character of the array.

One solution would be to convert it to std::string before giving it to stream.

t_smith
  • 89
  • 1
  • 1
  • 7
  • One line answer: std::string str(c_str, strnlen(c_str, max_length)); Here are few answers: https://stackoverflow.com/questions/8126498/how-to-convert-a-const-char-to-stdstring – t_smith Jun 03 '15 at 11:22
  • But msg is not declared as pointer array of chars, it is SQLWCHAR array. – Jan Bohac Jun 16 '15 at 08:13