【发布时间】:2012-10-31 02:11:31
【问题描述】:
我正在编写一个 ODBC 数据库类,它包含一个用于从给定查询中获取一系列属性和元组的成员函数。
我在下面的语句中有一行代码导致在调试模式下抛出此运行时错误:
Unhandled exception at <mem loc> in <prog name>: 0xC0000005: Access violation writing location <mem loc>.
这是ERROR 指出违规行的代码:
SQLINTEGER length = 0;
vector<vector<string>> data;
this->sReturn = SQLFetch(this->sHandle);
while (this->sReturn == SQL_SUCCESS) {
vector<string> tuple;
for (int i = 0; i < columnCount; i++) {
SQLPOINTER value = "";
switch (info[i].columnType) {
case 0 : //SQL_UNKNOWN_TYPE
throw DatabaseAttributeTypeUnknown("The database returned an attribute of an unknown type.");
break;
case 1 : //SQL_CHAR
this->sReturn = SQLGetData(this->sHandle, i + 1, info[i].columnType, value,
info[i].columnSize*sizeof(SQLCHAR),
ERROR &length);
break;
//Some more cases
}
}
知道为什么会抛出这个错误吗?这是MSDN documentation on SQLGetData(),它为length赋值。
感谢您的宝贵时间。
【问题讨论】:
标签: c++ sql exception odbc runtime-error