MySQL Forums
Forum List  »  Connector/C++

Unknown host error when using Connector/C++
Posted by: Kris Dahl
Date: December 22, 2008 09:57PM

Alright, I've been working at this about a week, and I've gotten beyond frustrated and I'm coming here for help and asking for help.

I'm fairly sure I've installed Connector/C++ installed properly, but I'm not really sure because almost every step of the installation instructions went completely, well, nothing like it was explained in the instructions. I know it's not my connection settings (as I can connect to MySQL from the command prompt or a Java program) so I don't know what I'm doing wrong.

When I try to establish a connection to my MySQL database, if I don't include a port number, I get an 11004 unknown host error. If I include the host number, it just crashes and burns without displaying the exception. Adding the "tcp://" at the beginning seems to cause trouble too...

I've tried the following:
1. Including every include folder I can find in any combination of all and/or only one of them.
2. Adding the mysqlcppconn.lib as an additional dependency
3. Added additional library directory

I've tried all of those in about every combination you can imagine, from just one of them to every one I can think of. These have had varying degrees of no effect or making it worse.

Again, this works fine with my Java/MySQL program, and perfectly from the console line. Here's my code, it's basically taken straight from the examples folder.

#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <stdexcept>

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

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

using namespace std;

int main()
try {

	sql::mysql::MySQL_Driver *driver;
	sql::Connection *connection;
	driver = sql::mysql::get_mysql_driver_instance();
	connection = driver->connect("", "root", "password");

} catch (sql::SQLException &e) {
		cout << "# ERR: SQLException in " << __FILE__;
		cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
		cout << "# ERR: " << e.what();
		cout << " (MySQL error code: " << e.getErrorCode();
		cout << ", SQLState: " << e.getSQLState() << " )" << endl;

		return EXIT_FAILURE;

Oh, and it doesn't seem to make a difference if I declare the host, user name, and password inside the function call or outside.

Please, please, please someone help me with this. I've been at it a week and I've gotten so frustrated and discouraged it's ridiculous.

Options: ReplyQuote

Written By
Unknown host error when using Connector/C++
December 22, 2008 09:57PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.