Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何修复';字符串太长';xdev C+中的错误+;连接到MySQL时的api_C++_Mysql - Fatal编程技术网

C++ 如何修复';字符串太长';xdev C+中的错误+;连接到MySQL时的api

C++ 如何修复';字符串太长';xdev C+中的错误+;连接到MySQL时的api,c++,mysql,C++,Mysql,我正在使用MySQL Connector/C++8.0.15连接MySQL数据库,当我在Visual Studio 2017中运行该示例时,它失败了,错误为“字符串太长” 高级”中将“字符集”配置为“使用多字节字符集” 我仔细检查了我是在x64和发布模式下构建的。看起来binites只是在发布模式下构建的 这解决了我的问题。希望能有所帮助。如果在您的mySession参数列表中使用usr.c_str()和pwd.c_str()会发生什么情况?我尝试了,但失败了,出现了相同的异常“字符串太长”

我正在使用MySQL Connector/C++8.0.15连接MySQL数据库,当我在Visual Studio 2017中运行该示例时,它失败了,错误为“字符串太长”

<我的操作系统Windows 10和我使用Visual Studio 2017,我只使用X DevAPI作为C++。
void test_XdevCPlus_demo()
{
    std::string usr = "root";
    std::string pwd = "1030";
    // Connect to MySQL Server on a network machine
    try
    {
        Session mySession(
            SessionOption::USER, usr,
            SessionOption::PWD, pwd,
            SessionOption::HOST, "localhost",
            SessionOption::PORT, 33060,
            SessionOption::DB, "test",
            SessionOption::SSL_MODE, SSLMode::DISABLED
        );

        Schema myDb = mySession.getSchema("test");
    }
    catch (mysqlx::Error::exception& e)
    {
        std::cout << e.what() << std::endl;
    }
}
void test\u XdevCPlus\u demo()
{
std::string usr=“root”;
std::string pwd=“1030”;
//连接到网络计算机上的MySQL服务器
尝试
{
会话我的会话(
会话选项::用户,usr,
会话选项::PWD,PWD,
SessionOption::HOST,“localhost”,
会话选项::端口,33060,
SessionOption::DB,“测试”,
SessionOption::SSL_模式,SSLMode::已禁用
);
Schema myDb=mySession.getSchema(“测试”);
}
catch(mysqlx::Error::exception&e)
{

std::cout我遇到了类似的问题。我使用Visual Studio 17遇到字符串转换异常。我通过以下步骤解决了该问题:

  • 我在“配置属性->高级”中将“字符集”配置为“使用多字节字符集”

  • 我仔细检查了我是在x64和发布模式下构建的。看起来binites只是在发布模式下构建的


  • 这解决了我的问题。希望能有所帮助。

    如果在您的
    mySession
    参数列表中使用
    usr.c_str()
    pwd.c_str()
    会发生什么情况?我尝试了,但失败了,出现了相同的异常“字符串太长”。我也有同样的问题。很高兴我遇到了这个问题。我会继续检查。
    string(const char *other)
        {
            if (!other)
                return;
            std::string utf8(other);
            -- > Impl::from_utf8(*this, utf8);
        }
    
    
        catch (std::exception &ex)
        {
            cout << "STD EXCEPTION: " << ex.what() << endl;
            return 1;
        }