0% found this document useful (0 votes)
24 views

Method To Make Mysql Work With Visual C

This document provides steps to connect a Visual C++ project to a MySQL database. It includes necessary header files, explains that the MySQL driver class is sql::mysql::MySQL_Driver rather than Driver, and lists required project properties like adding MySQL libraries as references and including directories. References that helped establish these steps are also provided.

Uploaded by

Hassan Al Tahan
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Method To Make Mysql Work With Visual C

This document provides steps to connect a Visual C++ project to a MySQL database. It includes necessary header files, explains that the MySQL driver class is sql::mysql::MySQL_Driver rather than Driver, and lists required project properties like adding MySQL libraries as references and including directories. References that helped establish these steps are also provided.

Uploaded by

Hassan Al Tahan
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Method to make mysql work with visual c++

Include the following in the main header file:

#include "stdafx.h"
#include <stdlib.h>
#include <iostream>

Include the following as well...

#include "mysql_connection.h"
#include "mysql_driver.h"

#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>

Unlike what the mysql tutorial claims to declare the driver with the Driver class, like so:

sql::Driver *driver;

whereas this seems to work...

sql::mysql::MySQL_Driver *driver;

The tutorial also says to get an instance of the driver with the get_mysql_driver_instance() method.
Something required in JDBC, but it appears to not be required here. Instead i connected directly to
the database with the necessary credentials usin the connect() method. So the
get_mysql_driver_instance() method does not get resolved by the linker (although the program
compiles fine).

The project properties are set as follows:-

• MySql.data.dll is added as a reference from the Connector/Net driver <path>\Assembly


folder. Under Common Properties.
• Common Language Runtime support is set to (/clr) under Configuration Properties.
• Additional include Directories is set to the MySql Server \include path under C/C++ >
General.
• Preprocessor Definitions has CPPCONN_PUBLIC_FUNC= added to the list under
Preprocessor.
• Additional Library Directories has <path>\lib\opt set also from the MySQL server path. This is
under Linker > General.
• Additional Dependencies have mysqlcppconn-static.lib and libmysql.lib set under Linker >
Input.

References that helped reach these conclusions:

http://msdn.microsoft.com/en-us/library/ec7sfckb%28VS.80%29.aspx

http://dev.mysql.com/doc/refman/5.1/en/connector-cpp-apps-windows-visual-studio.html
http://stackoverflow.com/questions/2128995/lnk2001-error-when-compiling-windows-forms-
application-with-vc-2008

http://forge.mysql.com/wiki/Connector_C%2B%2B#Getting_Started:_Usage_Examples

You might also like