1

First, I would like to say I've been lurking this site for years now, and I appreciate all that you've done to help me with C\C++.

The real issue I'm having, is I have made a program in windows that parses a yaml file, then queries a SQL database with the parsed info, and it worked fine. So I ported it over to linux, which appeared to have worked, save one problem. Whenever I test the program I get a Error 2005 saying it cannot find the host name. I've tried forcing the use of TCP, and still no avail. I've tried multiple databases, and the odd part is this works fine on windows, so if someone can shed light on the issue.

The error is specifically: Error: 2005: Unknown MySQL server host '#.#.#.#' (0)

Note: the #'s are just to censor the actual IP address.

I'm unsure what I'm doing wrong, and would like some help. My code is below.

int openConnection( char *name, char *password, char *ip, char *port, char *db )
{ 

    printf("Opening SQL Connection...\n");
    conn = mysql_init(NULL);
    if (conn == NULL)
            {
                    printf("Error: %u: %s\n", mysql_errno(conn), mysql_error(conn));
                    return 1;
            }

    if (mysql_real_connect(conn,
            ip,
            name,
            password,
            db,
            (int)port,
            NULL, 0) == NULL)
            {
                    printf("Error: %u: %s\n", mysql_errno(conn), mysql_error(conn));
                    return 2;
            }
    return 0;
}
  • Did you try pinging it, and testing the ports? – imreal Nov 14 '12 at 21:10
  • Yes, I've tried pinging it and used the ports for other things. I've connected to the database via heidisql to see if it was on my end, and It's with the program, which is what leaves me scratching my head. – Graham O'Grady Nov 14 '12 at 22:27
  • Are you prepending http? Did you try with mysql command line? – imreal Nov 14 '12 at 22:47
  • Yea I tried using the mysql command line, and no avail. I am pretty sure it's on my end, and not my program. Not using HTTP at all, just connecting to a database. I get the same error, unknown host =\. – Graham O'Grady Nov 15 '12 at 13:02
  • It is a long shot but your /etc/hosts file might bet bad. http://ubuntuforums.org/showthread.php?t=1278665 – imreal Nov 15 '12 at 17:57
  • I just tried the above, did 'nano /etc/hosts', only localhost was set, and after removing still no avail. edit: I can however use mysql -h to connect to it =/ – Graham O'Grady Nov 17 '12 at 01:09

0 Answers0