I agree !! An incredible waste of time and energy.
Answer is now even buried in the stack of info on forums.
But reason could be as simple as a difference in the std::string model between the supplied lib and the Microsoft std STL support for string. So it' may not have anything to do with optimization but just be a side effect of a difference in "understanding" the internals of a standardized type like std::string.
More precisely:
The connector always end up using the main connect method that use a std::map of string.
The other method (the one use is many example) involve 3 std::string for connection/username/pwd.
Theses 3 const std::strings will be passed as ref (&) and loaded in a std::map the main method will be called with that std::map.
It looks to be here that things go very wrong between debug and release version.
Because the Msoft debug version looks like adding some additional area in debug mode to help it's own diag and add it to the std::string, this make the internal debug safety checks done in main connect method to fail (even before loading the map)
Solution:
Rather tedious but feasible (I didn't find any better to keep debug version working):
- Get the src of the connector and recompile the project under VS (I still use VS2005) Then open the .sln generated automatically by cmake (BTW Cmake did a smart work).
I did inspire my recompilation effort of the connector from this excellent work
http://blog.ulf-wendel.de/?p=204 ,
but it's Cmake+ VS version dependent so don't be surprised to see difference in output with screen shoot, just apply the Cmake method and discard other work.
Don't be surprized or demotivated to see that It failed on 2 of the 29 subprojects. Even if reason it failed can be corrected they are a "don't care" kind of.
At least digging in the subdirectory ("MySrcDir/…/mysql-connector-c++-1.0.5\driver\debug" on my machine) you will find a beautiful new mysqlcppconn.lib it's DLL and mysqlcppconn-static.lib, all FINALLY COMPATIBLE with Visual Studio!! (Of course it was compiled with it) Once linked they allow all of the test sample code to run properly in debug mode.
It's even fancier if you keep the .idb/.pdb under your .exe dir as you can step into the .lib and see under the hood to understand all that's thing that the doc don't say.
Also remember that mysqlcppconn is nothing more than a wrapper for the basic C library, so the work done in the c++ part is not very elaborate. And you still need to link the libmysql.lib to get acess to MySQL. But the supplied one is an oldies and goldies code and are FAR MORE stable than this C++ connector (I used C connector rev 6.0.2)
Also valuable (why isn't this PDF part of the main online doc??!!)
http://downloads.mysql.com/docs/connector-cpp-en.pdf
I suspect that SUN as owner of MySQL AB, doesn't have in it's philosophy to look at Microsoft IDE with care, but making our life miserable will not make me falling in loving with their tools!!