Solved

compact and repair

Posted on 2001-08-21
6
511 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6409485
0
 

Author Comment

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

Expert Comment

by:ShaunWilde
ID: 6411330
I was under the impression you can use Jet to access ODBC
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:kukiya
ID: 6412347
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
ID: 6412439
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
ID: 6430188
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Expand macro to ask for filename column 8 40
Expand to include initial dialog with two choices. 9 94
move a line in eclipse 3 111
has77  challenge 9 105
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
Suggested Courses

751 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