使用VS Express 2013,MySQL Connector 1.1,C ++连接数据库

时间:2016-12-19 07:18:42

标签: c++ mysql visual-studio mysql-connector

尝试在MySQL中连接数据库时遇到问题。我正在使用VS Express 2013。 这是我的代码:

// Project_Test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

/* Standard C++ includes */
#include <stdlib.h>
#include <iostream>

/*
Include directly the different
headers from cppconn/ and mysql_driver.h + mysql_util.h
(and mysql_connection.h). This will reduce your build time!
*/
#include "mysql_connection.h"
#include "mysql_driver.h"

#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>

using namespace std;

int main(void)
{
cout << endl;
cout << "Started";

try {
    sql::Driver *driver;
    sql::Connection *con;
    sql::Statement *stmt;
    sql::ResultSet *res;

    /* Create a connection */
    driver = get_driver_instance();
    con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
    /* Connect to the MySQL test database */
    con->setSchema("schema_test");

    stmt = con->createStatement();
    res = stmt->executeQuery("SELECT * FROM table_test");
    while (res->next()) {
        cout << "\t... MySQL replies: ";
        /* Access column data by alias or column name */
        cout << res->getString("Name") << endl;
    }
    delete res;
    delete stmt;
    delete con;

}
catch (sql::SQLException &e) {
    cout << "# ERR: SQLException in " << __FILE__;
    cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
    cout << "# ERR: " << e.what();
    cout << " (MySQL error code: " << e.getErrorCode();
    cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}

cout << endl;

return EXIT_SUCCESS;
}

我发现了这些错误:

'Project_Test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file. 'Project_Test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file. 'Project_Test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file. 'Project_Test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp120.dll'. Cannot find or open the PDB file. 'Project_Test.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr120.dll'. Cannot find or open the PDB file. The thread 0x17b4 has exited with code -1073741701 (0xc000007b). The thread 0xce4 has exited with code -1073741701 (0xc000007b). The thread 0x1440 has exited with code -1073741701 (0xc000007b). The program '[5652] Project_Test.exe' has exited with code -1073741701 (0xc000007b).

它显示&#34;应用程序无法正确启动...&#34;当我运行它。 我已经在Google上搜索过了,但是没有解决方案。 我认为它是由x64和x64之间的不兼容造成的。 x86库。 我正在使用MySQL Server&amp; MySQL连接器x86但Visual Studio为x64构建。我试图在Configuration Manager中更改解决方案平台,但它只有x64平台,没有x86平台的选择。这是VS Express的错误吗? Anyidea要解决这个问题吗?

0 个答案:

没有答案