简体   繁体   中英

How to connect C++ to MySQL with OTL ODBC driver?

I'm having trouble connecting to my MySQL database using the OTL ODBC Driver on C++. I'm using Visual Studio 2019, and the problem appears to be on the connection string. My MySQL database is hosted on localhost with easyPHP, but I'll need to use an online database later, this first database is just for tests.

I tried multiple types of connection strings, but I think I didn't fully get what should I supply as the DSN

db.rlogon("root@127.0.0.1"); // connect to the database

I also tried

db.rlogon("root/@mysql"); // connect to the database

and

db.rlogon("root","","127.0.0.1:3306",0); // connect to the database

I expected it to connect, but it didn't, and I got this error:

"[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"

I managed to do it, I asked the creator of the OTL library and he helped me what to do:

In Windows 7, go to Control Panel > Administrative Tools > ODBC Data Sources (32-bit) or > ODBC Data Sources (64-bit)

And then you can create an ODBC DSN there, and it's what you need to provide for the connection.

Alternatively, you can use a connection string (He recommended me this website: https://www.connectionstrings.com/ )

Anyway, I got it to work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM