I am working on a project which creates a new MySQL database connection in C++. I am using the sql::ConnectOptionsMap to set the host, username, password etc to be able to pass this into the connect method but something odd is happening.
I am following the guide from https://dev.mysql.com/doc/connector-cpp/en/connector-cpp-connect-options.html
I have the following code:
sql::ConnectOptionsMap connection_properties; connection_properties["hostName"] = server.c_str(); connection_properties["userName"] = username.c_str(); connection_properties["password"] = password.c_str(); connection_properties["port"] = port; connection_properties["OPT_RECONNECT"] = true; if (!database.empty()) { connection_properties["schema"] = database.c_str(); } sql::Connection *conn = driver->connect(connection_properties);
Server, username, password and database are strings, I've tried with and without the c_str()
.
For some reason when running this the second element that attempts to get added to the connection_properties throws an exception. I.e. when stepping through the code, setting hostname is successfully done, then when it then steps over setting userName
I then get a read access violation and visual studio chucks me into a file called iosfwd
(this file is part of C++, its not within my project).
Its always the second element as I can comment out setting the hostName
then the userName
is successfully set but then when setting the password
I then get the same error again.
Thanks for any help you can provide.
UPDATE
I've tested this on Linux as well, and I was getting an error stating that it was expecting sql::SQLString, I then removed the c_str()
from each parameter and on Linux it now works perfectly fine.
The issue is only on Windows now and it seems to be crashing mysqlcpplib.dll for some reason.
0 comments:
Post a Comment