CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 4 of 4

Thread: Remote Mysql connection via visual C++

  1. #1
    Join Date
    Jan 2009

    Exclamation Remote Mysql connection via visual C++

    I have been trying to connect to my sql database, which is stored on a remote sever, and I can get code to compile but it will not connect to the database. Is there a difference between local host coding and remote connection coding? If so please provide the connection code necessary so I can connect to my database, Thank you!!

  2. #2
    Join Date
    Sep 2004
    Holland (land of the dope)

    Re: Remote Mysql connection via visual C++

    Install the MySql ODBC driver and you can use the CDatabase class to connect and the CRecordset class to query the data. AFAIK the ODBC connections don't mind the difference between a local or a remote connection.

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003

    Re: Remote Mysql connection via visual C++

    What error do you get? Does your code work with a local database?

  4. #4
    Join Date
    Jan 2009

    Re: Remote Mysql connection via visual C++

    This is the problem shown in my command window.....:

    "Can't connect to MySQL server on '' (10060)"

    My code i'm using is:

    #include "stdafx.h"
    #include <iostream>
    #include <windows.h>
    #include <mysql.h>
    #pragma comment(lib, "C:\\Program Files\\MySQL\\MySQL Server 6.0\\lib\\opt\\libmySQL.lib")

    using namespace std;

    #define host ""
    #define username "madhatba_admin"
    #define password "***"
    #define database "madhatba_scihas"
    MYSQL *connection, mysql;
    MYSQL_RES *result;
    MYSQL_ROW row;
    int query_state;

    int main()
    //Connecting to the Database
    connection = mysql_real_connect(&mysql,host,username,password,database,0,0,0);
    if (connection == NULL)
    cout << mysql_error(&mysql) << endl;
    return 1;

    mysql_query(connection,"SELECT * FROM 'repeater' WHERE 1"); //query the database
    result = mysql_use_result(connection);
    while ((row = mysql_fetch_row(result)));
    cout << row[1] << endl;

    return 0;


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)