I’m trying to connect to MySQL from my C++ program and I have downloaded and configured the MySQL C++ Connector in my project but it keeps causing two weird errors. For context, below is my code:
try {
driver = get_driver_instance();
conn = driver->connect("tcp://localhost:3306", "root", "");
if (conn) {
cout << "Successfully Connected to MySQL Database!" << endl;
}
else {
cerr << "Failed to Connect to MySQL Database." << endl;
}
}
catch (SQLException& e) {
cerr << "SQLException: " << e.what() << endl;
cerr << "MySQL error code: " << e.getErrorCode() << endl;
cerr << "SQLState: " << e.getSQLState() << endl;
}
In the console the output is:
SQLException: Unable to connect to (≈qK±:3306
MySQL error code: 0
SQLState:
And when I check visual studio I see the error displayed below that comes from a file called xstring on line 534:
Exception thrown at 0x00007FFF81BA0890 (ucrtbased.dll) in MyProgram.exe: 0xC0000005: Access violation reading location 0x00007F0045444F4D.
I’ve tried to replace ‘localhost’ with ‘127.0.0.1’ but there was still no luck and I just keep getting the same issue. I have no idea what could’ve caused this or how to fix it.
Dev00 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.