CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Feb 2003
    Location
    Bilbao
    Posts
    513

    MySQL Driver Connect

    Hi you all

    I am using Visual C++ to access a MySQL database. I am using the ODBC connector, and CRecordSet class from the MFC.

    I have included into a DLL all my accesses to the database, wrapping them with functions more or less like this.

    __DATAACCESS_API__ int get_meter2_data(meter2_t& meter2_data)
    {
    TRY {
    CTableMeter2 oTableMeter2;
    if (oTableMeter2.Open() == 0) {
    return -1;
    }

    if (oTableMeter2.GetRecordCount() == 0) {
    oTableMeter2.Close();
    return -1;
    }

    oTableMeter2.MoveFirst();
    meter2_data.sn = oTableMeter2.m_meter_sn;
    meter2_data.cct_sn = oTableMeter2.m_cct_sn;

    oTableMeter2.Close();
    } CATCH(CDBException, e) {
    return -1;
    } END_CATCH

    return 0;
    }


    My problem is that most of the time these functions work, but sometimes it is displayed the "Connector ODBC Driver Connect" screen (with correct values).

    I can accept the values and the application continues working, but...

    All help is wellcome.

    Thanks.

    Miguel Ángel
    Caronte
    Si tiene solución... ¿por qué te preocupas?
    Si no tiene solución... ¿por qué te preocupas?

  2. #2
    Join Date
    Feb 2006
    Location
    Croatia - Zagreb
    Posts
    459

    Re: MySQL Driver Connect

    What you are expiriencing is probably a ODBC fault when it can't connect to MySQL base, try to catch it in exeption and then try to recconect again. If the proble persist I would recomend then you start using MySQL c-API provided with all MySQL implementation, It Is very good and it is pretty low level so it is up to you to design wrappers any way you want. Also I will presume that you will have problems with ODBC when trying to execute stored procedures and triggrers.
    You just divided by zero, didn't you?

  3. #3
    Join Date
    Feb 2003
    Location
    Bilbao
    Posts
    513

    Re: MySQL Driver Connect

    Yes... I understand that the correct way to solve the problem would be in a try... catch.

    Am I doing it wrong in my previous code?
    Caronte
    Si tiene solución... ¿por qué te preocupas?
    Si no tiene solución... ¿por qué te preocupas?

  4. #4
    Join Date
    Mar 2005
    Location
    Romania,Cluj-Napoca
    Posts
    1,073

    Re: MySQL Driver Connect

    Hi....if you want a wrapper
    Ovidiu has a good article have a look.
    Please use code tags [code] [/code]

    We would change the world, but God won't give us the sourcecode..
    Undocumented futures are fun and useful....
    ___
    ______
    Gili

  5. #5
    Join Date
    Feb 2003
    Location
    Bilbao
    Posts
    513

    Re: MySQL Driver Connect

    In other case I would have take into account the idea of this wrapper. However in this case I have no much time to get the solution (I will do a remake of the application next month, but at the moment...).

    I am trying to use OpenEx instead of Open, and use the flag CDatabase::noOdbcDialog.

    Do you consider it a good solution?
    Caronte
    Si tiene solución... ¿por qué te preocupas?
    Si no tiene solución... ¿por qué te preocupas?

  6. #6
    Join Date
    Apr 2001
    Location
    Tampa Florida
    Posts
    233

    Re: MySQL Driver Connect

    Hello
    If you are using MySQL you might want to check that the tables are searchable
    To do this the MyISAM is acceptable
    Regards
    "trampling out the vintage"

  7. #7
    Join Date
    Feb 2003
    Location
    Bilbao
    Posts
    513

    Re: MySQL Driver Connect

    Sorry, but this is the first time that I work with a database. What is MYISAM?
    Caronte
    Si tiene solución... ¿por qué te preocupas?
    Si no tiene solución... ¿por qué te preocupas?

  8. #8
    Join Date
    Mar 2005
    Location
    Romania,Cluj-Napoca
    Posts
    1,073

    Re: MySQL Driver Connect

    Here is some reference
    MYISAM
    Please use code tags [code] [/code]

    We would change the world, but God won't give us the sourcecode..
    Undocumented futures are fun and useful....
    ___
    ______
    Gili

  9. #9
    Join Date
    Feb 2003
    Location
    Bilbao
    Posts
    513

    Re: MySQL Driver Connect

    I have read something about MyISAM and InnoDB, and this last seems to be more reliable.

    Am I wrong?
    Caronte
    Si tiene solución... ¿por qué te preocupas?
    Si no tiene solución... ¿por qué te preocupas?

  10. #10
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: MySQL Driver Connect

    Quote Originally Posted by Caronte
    I have read something about MyISAM and InnoDB, and this last seems to be more reliable.
    Yeah, that's because unlike MyISAM, InnoDB supports foreign keys and transactions.
    But, AFAIK it costs more if you want to redistribute MySQL with your application.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  11. #11
    Join Date
    Feb 2003
    Location
    Bilbao
    Posts
    513

    Re: MySQL Driver Connect

    I have tried a lot of things to solve my initial problem, but finally it seems that the problem is in using a query to open a table...

    I mean... the dialog does not seem to appear whe I do someting like:

    oTableMeter2.Open();

    but appears when I do

    char szQuery[SQUERY_SIZE];
    wsprintf(szQuery, "SELECT * FROM contadores2 WHERE cct_sn=%lu AND meter_sn=%lu", cct_sn, meter_sn);
    oTableMeter2.Open(CRecordset::snapshot, szQuery);

    Thanks
    Caronte
    Si tiene solución... ¿por qué te preocupas?
    Si no tiene solución... ¿por qué te preocupas?

  12. #12
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: MySQL Driver Connect

    Quote Originally Posted by g_gili
    Hi....if you want a wrapper
    Ovidiu has a good article have a look.
    I would like to recommend it also, not because is my article but first is much more faster than MFC ODBC classes, CDatabase, CRecordset and so on which are really, really slow.
    Quote Originally Posted by Caronte
    In other case I would have take into account the idea of this wrapper. However in this case I have no much time to get the solution (I will do a remake of the application next month, but at the moment...).
    IMO, it request less time to dig and implement than ODBC classes.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured