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
Solved

compact and repair

Posted on 2001-08-21
6
508 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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