Solved

compact and repair

Posted on 2001-08-21
6
501 Views
Last Modified: 2013-11-20
hi
I have a question.
I built an MFC application that connects to an access database by ODBC connection.
I also created MFC classes that inherits the CRecordset
class.

The problem is that when I delete all the records in a certain table, the size of the database does not get smaller.
I need to compact and repair the database.
My question is if there any way to update the size of the mdb database by SQL qurey or by any other way...

thanks alot !!!!
0
Comment
Question by:kukiya
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:ShaunWilde
Comment Utility
0
 

Author Comment

by:kukiya
Comment Utility
Thanks,
The point is taht I need to work with the ODBC connection
0
 
LVL 9

Expert Comment

by:ShaunWilde
Comment Utility
I was under the impression you can use Jet to access ODBC
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:kukiya
Comment Utility
sorry but I'm not sure I understand.

I would like to know if I can execute the command to comapct and repair the mdb file whenever I would like via the visual c++ source code....

0
 
LVL 9

Expert Comment

by:ShaunWilde
Comment Utility
what I am saying is that I don't think you can via MFC - you will have to go via Jet - did you look at the articles I posted?
0
 
LVL 2

Accepted Solution

by:
bkdc earned 50 total points
Comment Utility
In order to compact a database (especially access) you are required to close it first. And since it is closed, it's kinda difficult to compact it using SQL queries.

M$ stuff:


For example, the following code segment would create a .MDB file, repair
it, compress it to a second file, compress it in the same location, and
then create a datasource for it.

   void Config_Sample(void)
   {
             RETCODE retcode;
             int     subscrp;
     extern  HWND    hWnd;      /* Main window handle. */

     UCHAR szDriver[] = "Microsoft Access Driver (*.mdb)";
     UCHAR *szAttributes2[] =
     // Create the original .mdb file.
     {"CREATE_DB=c:\\odbcsdk\\smpldata\\access\\general.mdb General\0\0",

     // Issue a REPAIR_DB on the created file.
     "REPAIR_DB=c:\\odbcsdk\\smpldata\\access\\general.mdb\0\0",

     // Compact the file into a new location.
     "COMPACT_DB=c:\\odbcsdk\\smpldata\\access\\general.mdb "
       "c:\\odbcsdk\\smpldata\\access\\general2.mdb General\0\0",

     // Compact the file onto itself.
     "COMPACT_DB=c:\\odbcsdk\\smpldata\\access\\general.mdb "
       "c:\\odbcsdk\\smpldata\\access\\general.mdb General\0\0",

     // Create a datasource for the first .mdb file created.
     "DSN=albacc\0FIL=MS Access\0JetIniPath=odbcddp.ini\0"
     "DBQ=c:\\odbcsdk\\smpldata\\access\\general.mdb\0"
     "DefaultDir=c:\\odbcsdk\\smpldata\\access\0\0"};

     for (subscrp = 0;
          subscrp <= ((sizeof szAttributes2 / sizeof(UCHAR *)) - 1);
           subscrp++)
     {
       retcode = SQLConfigDataSource(hWnd,
                                     ODBC_ADD_DSN,
                                     szDriver,
                                     szAttributes2[subscrp]);
       if (retcode != TRUE)
         handle_error(retcode);
     }
     return;
   }
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
conditional code and condition difference 9 65
twoTwo  challenge 35 86
zeroMAx challenge 20 76
sumHeights  challenge 17 59
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now