SQLGetDiagRec 导致 Unicode 发行版崩溃

发布于 2024-07-19 11:57:14 字数 967 浏览 4 评论 0原文

我在调用 SQLGetDiagRec 时遇到问题。 它在 ascii 模式下工作正常,但在 unicode 模式下它会导致我们的应用程序崩溃,我只是不明白为什么。 我能找到的所有文档似乎都表明它应该在内部处理 ascii/unicode 开关。 我使用的代码是:

void clImportODBCFileTask::get_sqlErrorInfo( const SQLSMALLINT _htype, const SQLHANDLE _hndle )
{
SQLTCHAR      SqlState[6];
SQLTCHAR      Msg[SQL_MAX_MESSAGE_LENGTH];
SQLINTEGER    NativeError;
SQLSMALLINT   i, MsgLen;
SQLRETURN     nRet;

memset ( SqlState, 0, sizeof(SqlState) );
memset ( Msg, 0, sizeof(Msg) );

// Get the status records.
i = 1;

//JC - 2009/01/16 - Start fix for bug #26878
m_oszerrorInfo.Empty();

nRet = SQLGetDiagRec(_htype, _hndle, i, SqlState, &NativeError, Msg, sizeof(Msg), &MsgLen);
m_oszerrorInfo = Msg;
}

一切正常,直到该函数尝试返回,然后应用程序崩溃。 在调用 get_sqlErrorInfo 之后,它永远不会返回到代码行。

我知道这就是问题所在,因为我已经放入了诊断代码,它顺利通过了 SQLGetDiagRec 并且完成了这个函数。

如果我评论 SQLGetDiagRec 行,它就可以正常工作。

无论是运行发布还是调试,它在我的开发盒上始终运行良好。

对于这个问题的任何帮助将不胜感激。 谢谢

I'm having a problem with the call to SQLGetDiagRec. It works fine in ascii mode, but in unicode it causes our app to crash, and i just can't see why. All the documentation i've been able to find seems to indicate that it should handle the ascii/unicode switch internally. The code i'm using is:

void clImportODBCFileTask::get_sqlErrorInfo( const SQLSMALLINT _htype, const SQLHANDLE _hndle )
{
SQLTCHAR      SqlState[6];
SQLTCHAR      Msg[SQL_MAX_MESSAGE_LENGTH];
SQLINTEGER    NativeError;
SQLSMALLINT   i, MsgLen;
SQLRETURN     nRet;

memset ( SqlState, 0, sizeof(SqlState) );
memset ( Msg, 0, sizeof(Msg) );

// Get the status records.
i = 1;

//JC - 2009/01/16 - Start fix for bug #26878
m_oszerrorInfo.Empty();

nRet = SQLGetDiagRec(_htype, _hndle, i, SqlState, &NativeError, Msg, sizeof(Msg), &MsgLen);
m_oszerrorInfo = Msg;
}

everything is alright until this function tries to return, then the app crashes. It never gets back to the line of code after the call to get_sqlErrorInfo.

I know that's where the problem is because i've put diagnostics code in and it gets past the SQLGetDiagRec okay and it fnishes this function.

If i comment the SQLGetDiagRec line it works fine.

It always works fine on my development box whether or not it's running release or debug.

Any help on this problem would be greatly appreciated.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

作业与我同在 2024-07-26 11:57:14

好吧,我找到了正确的答案,所以我想我会将其放在这里以供将来参考。 我看到的文档是错误的。 SQLGetDiagRec 不处理 Unicode,我需要使用 SQLGetDiagRecW。

Well i found the correct answer, so I thought i would include it here for future reference. The documentation i saw was wrong. SQLGetDiagRec doesn't handle Unicode i needed to use SQLGetDiagRecW.

何以心动 2024-07-26 11:57:14

问题可能出在 sizoef(Msg) 中。 它应该是字符数:

sizeof(Msg)/sizoef(TCHAR)

The problem is probably in the sizoef(Msg). It should be the number of characters:

sizeof(Msg)/sizoef(TCHAR)
各自安好 2024-07-26 11:57:14

几个可能的问题。 首先,当你说:

m_oszerrorInfo = Msg;

m_oszerrorInfo 的类型是什么? 如果它是一个指针,则您将存储一个指向局部变量 (Msg) 的指针。 如果您稍后使用该指针,Msg 将不再存在。

其次,以下划线开头的名称在命名空间范围内为编译器保留。 为了不必担心这意味着什么,请勿使用以下划线开头的名称。

A copuple of possible problems. First, when you say:

m_oszerrorInfo = Msg;

what is the type of m_oszerrorInfo? If it is a pointer, you are storing a pointer to a local variable (Msg). If you use that pointer later, Msg will no longer exist.

Secondly, names that begin with an underscore are rerved for the compiler at namespace scope. In order not to have to worry about what this means, don't use names that begin with underscores.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文