【发布时间】:2015-04-12 07:30:36
【问题描述】:
我正在为一个不太流行的 mmorpg 游戏编写服务器-emu 软件,并且我正在使用 mysql connector for c++ 来连接我的数据库。重新安装 Windows(以及我的整个开发环境)后,我遇到了一个奇怪的 mysql 连接器异常。
我用来连接数据库的代码如下所示:
try
{
this->driver = get_driver_instance();
std::cout << "SQL Driver Name: " << this->driver->getName() << std::endl;
std::cout << "Connecting as " << user << "@" << host << " using password " << password << std::endl;
this->connection = this->driver->connect(host, user, password);
std::cout << "Setting schema to " << schema << std::endl;
this->connection->setSchema(schema);
} catch(sql::SQLException &e)
{
std::cout << "# ERR: SQLException in " << __FILE__;
std::cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << std::endl;
std::cout << "# ERR: " << e.what();
std::cout << " (MySQL error code: " << e.getErrorCode();
std::cout << ", SQLState: " << e.getSQLState() << " )" << std::endl;
return 1;
}
(所有变量,如用户、密码等都是 std::strings)
这之前可以工作,但现在它在控制台中打印:
SQL Driver Name: MySQL Connector C++ (libmysql)
Connecting as root@tcp://localhost:3306 using password testpassword
Setting schema to testschema
ERR: SQLException in c:\whatever\db.cpp on line 22
ERR: MySQL_Connection::setReadOnly() (MySQL error code: 0, SQLState: )
没有这一行:
this->connection->setSchema(schema);
一切正常。
我不知道如何解决这个问题以及为什么会发生这种情况。请帮忙。
【问题讨论】:
-
这里有同样的问题,但在 Ubuntu 上运行。它以前可以工作,但现在它给出了同样的错误。删除 setSchema 有时会起作用,但有时我会得到“未选择数据库”。快把我逼疯了!
-
您是否偶然找到了解决方案?我也有同样的问题!
标签: c++ mysql exception schema connector