res-> getString(1)mysql连接器崩溃调试

时间:2015-04-02 13:03:43

标签: c++ mysql

我在调试模式下使用mysql连接器c ++和visual studio时遇到问题。它编译得很好。我的算法适用于发布模式。当我切换到调试模式时,他遵守但是在跑步时他崩溃了。 我相信每次使用res-> getString()时他都会崩溃。 我使用visual studio 2013,mysql connector.C ++ 1.1。我已经添加了依赖项

  • C:\ Program Files \ MySQL \ Connector.C ++ 1.1 \ lib \ debug
  • C:\ Program Files \ Boost SDK;
  • C:\ Program Files \ MySQL \ Connector.C ++ 1.1 \ include
  • mysqlcppconn.lib和mysqlcppconn.dll
  • CPPCONN_PUBLIC_FUNC =; HAVE_INT8_T = 1(关于处理器定义)
  • 运行时库:/ MDd(唯一认为有效) 我在项目的调试目录中复制了mysqlcppconn.lib和mysqlcppconn.dll

使用此配置,我的程序在发布模式下工作(将Connector.C ++ 1.1 \ lib \ debug更改为Connector.C ++ 1.1 \ lib \ opt)。

在调试模式下,他说Debug Assertion失败了:

  • 文件:f:\ dd \ vctools \ crt \ crtw32 \ misc \ dbgheap.c
  • 第1322行
  • 表达式:_CrtIsValidHeapPointer(pUserData)
  • 按Rety调试应用程序 然后我不得不选择一个buttom(忽略;重启;离开)。当我按下忽略时,他继续跑,我有第一个结果,但他再次崩溃

这是我的代码部分

{

#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <memory>
#include <string>
/* MySQL Connector/C++ specific headers */
#include <cppconn/driver.h>
#include <cppconn/connection.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>
#include <cppconn/resultset.h>
#include <cppconn/metadata.h>
#include <cppconn/resultset_metadata.h>
#include <cppconn/exception.h>
#include <cppconn/warning.h>
#include "mysql_connection.h"
using namespace std;
using namespace sql;

int main(int argc, const char **argv)
{

     const char*                    str_DataBaseMarketData_Server = "root";

      const char*                   str_DataBaseMarketData_User = "root";
      const char*                   str_DataBaseMarketData_Password ="root";
      const char*                   str_DataBaseMarketData_Database ="bd test";

    cout << "Connector/C++ tutorial framework..." << endl;
    cout << endl;

    string fld;
    try {
        sql::Driver* driver = get_driver_instance();
        std::auto_ptr<sql::Connection> con(driver->connect(str_DataBaseMarketData_Server, str_DataBaseMarketData_User, str_DataBaseMarketData_Password));
        con->setSchema(str_DataBaseMarketData_Database);
        std::auto_ptr<sql::Statement> stmt(con->createStatement());

        sql::SQLString *data = new SQLString();
        std::auto_ptr<sql::ResultSet> res(stmt->executeQuery("SELECT * FROM news "));
        //ResultSetMetaData *res_meta = res->getMetaData();
        //cout << res_meta->getColumnDisplaySize( 1) << endl << endl;
        while (res->next()){

            fld = res->getString(2).c_str();
        }
    }
    catch (sql::SQLException &e) {
        /*
        The MySQL Connector/C++ throws three different exceptions:

        - sql::MethodNotImplementedException (derived from sql::SQLException)
        - sql::InvalidArgumentException (derived from sql::SQLException)
        - sql::SQLException (derived from std::runtime_error)
        */
        cout << "# ERR: SQLException in " << __FILE__;
        cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
        /* Use what() (derived from std::runtime_error) to fetch the error message */
        cout << "# ERR: " << e.what();
        cout << " (MySQL error code: " << e.getErrorCode();
        cout << ", SQLState: " << e.getSQLState() << " )" << endl;
        return EXIT_FAILURE;
    }

    cout << "Done." << endl;
    return EXIT_SUCCESS;
}

}

这件事让我变得疯狂,因为当我用其他任何东西取代getString()时,它会很甜蜜。你能帮我吗? 我在32位下运行。

0 个答案:

没有答案