Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2003
    Posts
    2

    Unanswered: Using OpenFromInitializationString to Open Database

    Hi. I know somebody has probably answered this before, but I searched the archives way back and couldn't find an answer.

    I'm trying to connect to a MySQL database in VC++ 7.0. Before I explain my problem, let me drop these facts. My MySQL database is running fine, and I can connect to it with VB without any problems. So I know that my ODBC driver is working and that the database is functioning. So, when I have the following code, I am totally lost as to what the problem is (sorry if the formatting stinks):

    CDataSource connection;
    CSession session;

    CTable< CAccessor<CTeam> > teams;

    HRESULT hr;
    hr = connection.OpenFromInitializationString(L"Provider =MSDASQL.1;Persist Security Info=False;Extended Properties=\"DRIVER={MySQL ODBC 3.51 Driver};DESC=;DATABASE=bsim;SERVER=localhost;UID=r oot;PASSWORD=;PORT=;OPTION=;STMT=;\"");
    if ( FAILED(hr) )
    {
    cout << "CDataSource open failed.\n" << endl;
    return 0;
    }

    The string that I'm using to try to connect with is the one that the VC wizard created for me. In that wizard, I selected the option to "Test Connection" and the connection worked fine. But in my program, opening the connection fails every time. Does somebody know what the problem might be? Is there an easier way to connect to a MySQL database from VC++ 7.0 than this?

    Thanks.

  2. #2
    Join Date
    Jul 2003
    Posts
    2

    Re: Using OpenFromInitializationString to Open Database

    Figured it out myself. Forgot the CoInitialize().

  3. #3
    Join Date
    Aug 2003
    Posts
    1

    Unhappy Re: Using OpenFromInitializationString to Open Database

    Hi,
    I have the same problem, but didn't manage to make it work yet..
    Could you send me a complete code that shows me how to connect to a MS Access db without any user or password info ?
    Thanks !
    Regards,
    fov

Posting Permissions

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