Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC+DAO database, 0 records inspite of data in file

MFC+DAO database, 0 records inspite of data in file

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasesysadminhelpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    samiujan
    wrote on last edited by
    #1

    :confused: Hi, In a nutshell: If i kill an MFC+DAO based server application while it is updating records using ctrl-c, the application exits and the database shows 0 records even though, 2 seconds ago, DaoRecordset::RecordCount() was returning 1000. It listens for messages on a socket and updates a RecordSet in table "CallLog". During update, I can see that RecordSet_for_CallLog.GetRecordCount() returns 10, 11 & 12 etc. records as messages are received over the socket, parsed and updated in the dbase. The problem occurs when I close the application midway while it is updating the Recordset. I can see that previous calls to GetRecordCount() were returning 10, 11, 12 etc. but when I open the database file in MS Access, there are no records in the table CallLog. If I open the file in Notepad, I can see the Record data in a jumbled form somewhere. So I guess, for some reason, MS Access garbles up the file while exiting, can someone tell me why? I need to handle this to avoid accidental failure. The main class is not derived from CWinApp. I call the constructor and methods directly in _tmain(). I made the application using the "Win32 Console Application" option in the New project Wizard and later checked the option for MFC support.

    J J 2 Replies Last reply
    0
    • S samiujan

      :confused: Hi, In a nutshell: If i kill an MFC+DAO based server application while it is updating records using ctrl-c, the application exits and the database shows 0 records even though, 2 seconds ago, DaoRecordset::RecordCount() was returning 1000. It listens for messages on a socket and updates a RecordSet in table "CallLog". During update, I can see that RecordSet_for_CallLog.GetRecordCount() returns 10, 11 & 12 etc. records as messages are received over the socket, parsed and updated in the dbase. The problem occurs when I close the application midway while it is updating the Recordset. I can see that previous calls to GetRecordCount() were returning 10, 11, 12 etc. but when I open the database file in MS Access, there are no records in the table CallLog. If I open the file in Notepad, I can see the Record data in a jumbled form somewhere. So I guess, for some reason, MS Access garbles up the file while exiting, can someone tell me why? I need to handle this to avoid accidental failure. The main class is not derived from CWinApp. I call the constructor and methods directly in _tmain(). I made the application using the "Win32 Console Application" option in the New project Wizard and later checked the option for MFC support.

      J Offline
      J Offline
      John Clump
      wrote on last edited by
      #2

      Not sure if you know this already or not, so please forgive me if it is obvious. Try calling the CDaoWorkspace::RepairDatabase function. Set up a CDaoWorkspace with your database, then call the function. I believe this will fix your problem. The other way I can think of is it to make a copy of the database (use the compactdatabase function of CDaoWorkspace), set a flag, then if the update is successful reset the flag. If the machine crashes, it will check that flag, and if set will erase the old database and replace it with the new. These only work with Jet databases, but you mentioned access so I assume they are always Jet databases ;)

      S 1 Reply Last reply
      0
      • S samiujan

        :confused: Hi, In a nutshell: If i kill an MFC+DAO based server application while it is updating records using ctrl-c, the application exits and the database shows 0 records even though, 2 seconds ago, DaoRecordset::RecordCount() was returning 1000. It listens for messages on a socket and updates a RecordSet in table "CallLog". During update, I can see that RecordSet_for_CallLog.GetRecordCount() returns 10, 11 & 12 etc. records as messages are received over the socket, parsed and updated in the dbase. The problem occurs when I close the application midway while it is updating the Recordset. I can see that previous calls to GetRecordCount() were returning 10, 11, 12 etc. but when I open the database file in MS Access, there are no records in the table CallLog. If I open the file in Notepad, I can see the Record data in a jumbled form somewhere. So I guess, for some reason, MS Access garbles up the file while exiting, can someone tell me why? I need to handle this to avoid accidental failure. The main class is not derived from CWinApp. I call the constructor and methods directly in _tmain(). I made the application using the "Win32 Console Application" option in the New project Wizard and later checked the option for MFC support.

        J Offline
        J Offline
        Jon Hulatt
        wrote on last edited by
        #3

        The update occurs in a transaction. If the transaction is interupted before completion, it is rollbacked. Signature space for rent. Apply Within.

        1 Reply Last reply
        0
        • J John Clump

          Not sure if you know this already or not, so please forgive me if it is obvious. Try calling the CDaoWorkspace::RepairDatabase function. Set up a CDaoWorkspace with your database, then call the function. I believe this will fix your problem. The other way I can think of is it to make a copy of the database (use the compactdatabase function of CDaoWorkspace), set a flag, then if the update is successful reset the flag. If the machine crashes, it will check that flag, and if set will erase the old database and replace it with the new. These only work with Jet databases, but you mentioned access so I assume they are always Jet databases ;)

          S Offline
          S Offline
          samiujan
          wrote on last edited by
          #4

          Hello, thanx for the info. I tried repairing the database thru the API as well the Tools->Database Utilities->Compact & Repair, neither is any good. Thanx for Tip 2, but that is good for checking AFTER the program, i need to make sure the data is not corrupted before this happens. This only happens when I close the application while it is listening to msgs over a TCP socket AND updating the database. If i close the sender first and close this receiver application everything is fine, otherwise, the table is empty. there was an exception in CDAOCore.cpp earlier at Line 39, but that was supposed to be a bug in MFC and I fixed it by compiling the code with MFC statically. i have been programming for a long time but this has really got me in a fix, i cannot see a pattern here at all. :confused:

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups