我想使用cppconn库连接到我的azure SQL数据库。不幸的是我收到了这个错误(由于隐私原因,路径被部分遮挡了):
# ERR: SQLException in ###/Monitor app/src/liteDatabase.cpp(azureTest) on line 38
# ERR: Lost connection to MySQL server at 'reading initial communication packet', system error: 104 (MySQL error code: 2013, SQLState: HY000 )
我已使用sudo iptables -A INPUT -i eth0 -p tcp -m tcp --dport 1433 -j ACCEPT
该方法的代码如下所述。
std::cout << std::endl;
std::string query = "SELECT * FROM azureDatabase.db_accessadmin.signals;";
std::cout << "Running " << query << std::endl;
try
{
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
/* Create a connection */
driver = get_driver_instance();
con = driver->connect("###.database.windows.net:1433", "###", "###");
/* Connect to the MySQL test database */
con->setSchema("azureDatabase");
stmt = con->createStatement();
res = stmt->executeQuery(query);
while (res->next()) {
std::cout << "\t... MySQL replies: ";
/* Access column data by alias or column name */
std::cout << res->getString("_message") << std::endl;
std::cout << "\t... MySQL says it again: ";
/* Access column data by numeric offset, 1 is the first column */
std::cout << res->getString(1) << std::endl;
}
delete res;
delete stmt;
delete con;
}
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;
}
std::cout << std::endl;
可能出现什么问题?