Solved

compact and repair

Posted on 2001-08-21
6
506 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
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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
bobThere java chalenge 45 92
Use of condition with 'serial' in ansible 2 61
unix example issues 18 90
Not needed 13 112
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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