Thread: MSAccess Database

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    8

    MSAccess Database

    Is there any information or example of how to compact an MSAcess Database using C.

    I have found documentation for VB like crazy .. but does me no good.

    Any help would be great.

    I need to create a dll to contain a method to compact the database.

    Thanks!
    -Deb

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What methods are they suggesting in VB? Since the actual database is the same, it should be the same principle for C and for VB.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Code:
    //Compile: cl.exe compact.cpp /MT /EHsc
    
    #include <afx.h>
    
    //Type library for ADO 2.6.
    #import "C:\PROGRAM FILES\COMMON FILES\System\ado\Msado26.tlb" no_namespace rename ("EOF","adoEOF")
    //Microsoft Jet and Replication Objects Library 
    #import "C:\PROGRAM FILES\COMMON FILES\System\ado\MSJRO.DLL" 
    
    int main(void)
    {
    	try
    	{
    		CoInitialize(0);
    		JRO::IJetEnginePtr jet(__uuidof(JRO::JetEngine));
    		jet->CompactDatabase( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\Source.MDB",
    			"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\Dest.mdb");
    		CoUninitialize();
    	}
    	catch(_com_error &e)
    	{
    		CString csError;
    		csError =(LPCTSTR) e.Description();
    		printf("%s\n", csError);
    
    	}
    	return 0;
    }

  4. #4
    Registered User
    Join Date
    Oct 2007
    Posts
    8
    Thanks. That is almost what I need... except 2 things..

    I don't have anything more than a Borland Command Line Compiler... which I used to learn how to create dll's but I've used C code and not C++.

    I have no afx.h file.

    More help ??

  5. #5
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    The afx.h header file was just for the try/catch block. I don't think it can get any more basic than the following example without the afx.h file:

    //
    Code:
    Compile: cl.exe compact.cpp /MT 
    
    //Type library for ADO 2.6.
    #import "C:\PROGRAM FILES\COMMON FILES\System\ado\Msado26.tlb" no_namespace rename ("EOF","adoEOF")
    //Microsoft Jet and Replication Objects Library 
    #import "C:\PROGRAM FILES\COMMON FILES\System\ado\MSJRO.DLL" 
    
    int main(void)
    {
    		CoInitialize(0);
    		JRO::IJetEnginePtr jet(__uuidof(JRO::JetEngine));
    		jet->CompactDatabase( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\Source.MDB",
    			"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\Dest.mdb");
    		CoUninitialize();
    	return 0;
    }

  6. #6
    Registered User
    Join Date
    Oct 2007
    Posts
    8
    I know it's only a few lines, but ... if I use Borland to compile it... I get the following:


    Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
    compact.c:
    Error E2503 compact.c 4: Missing or incorrect version of TypeLibImport.dll
    Error E2503 compact.c 6: Missing or incorrect version of TypeLibImport.dll
    Warning W8065 compact.c 10: Call to function 'CoInitialize' with no prototype in function main
    Error E2451 compact.c 11: Undefined symbol 'JRO' in function main
    Error E2379 compact.c 11: Statement missing ; in function main
    Error E2451 compact.c 12: Undefined symbol 'jet' in function main
    Warning W8065 compact.c 14: Call to function 'CoUninitialize' with no prototype in function main
    *** 5 errors in Compile ***

  7. #7
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    I believe you may have an old (or possibly corrupted) MDAC (Microsoft Data Access Component) installed. MDAC is Microsoft middleware that contains Jet which is the database engine used by MS Access and is needed to access data in MDB format.

    I would suggest you use the components checker to review your system and download any needed updates. The component checker and updates can be found at MS Components.

    As a last resort, you can download Msado26.tlb and Msjro.dll from the internet and try to compile/run your app. I have never tried this approach and do not recommend it.

  8. #8
    Registered User
    Join Date
    Oct 2007
    Posts
    8
    Question... Does this code compile for you?

  9. #9
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Question... Does this code compile for you?
    Both simple, complete examples do compile without any problem. Both examples correctly compact a MS Access 2003 SP2 database. But I am using a MS compiler with MDAC version 2.8 with SP2. I always test code before I post it on a board.

  10. #10
    Registered User
    Join Date
    Oct 2007
    Posts
    8
    Okay, that's kewl. It's do-able. )

    Now, I guess I need to figure out what I need to get in order to compile this file and create a dll.

    Can you guide me?

  11. #11
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    First of all, my caveat. I have absolutely no experience with the line of Borland products. But I did download the freeware command line compiler. It did generate the same errors that you encountered when I compiled the source.

    I reviewed the Borland C++ builder developers guide and chapter 5 has info on how to import the type libraries etc via a project. It appears that you may need the C++ builder for your project since the freeware command line compiler is very stripped down, capable of little more than compiling basic C programs. Please keep in mind that this is only my opinion and that I have absolutely no experience with the Borland products.

  12. #12
    Registered User
    Join Date
    Oct 2007
    Posts
    8
    Thanks. I appreciate your help, and especially going the extra step to get the Borland Compiler!!!

    So double thanks!!

    The last time I downloaded Visual C++, the program wouldn't work for me and it frooze on uninstall.

    Let me see what I can do... I may be back for more help )

    Again, you're awesome.

  13. #13
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    If you wish, I'll write the dll and provide the source to the dll. This way you can implement the dll in your Borland command line compiler code until you get a functioning MS compiler. PM me if you wish to pursue this option.

  14. #14
    Registered User
    Join Date
    Oct 2007
    Posts
    8
    Thanks for all your help Bob!

  15. #15
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Don't forget to share the solution with everyone.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. literature database: help with planning
    By officedog in forum C++ Programming
    Replies: 1
    Last Post: 01-23-2009, 12:34 PM
  2. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 01:09 PM
  3. Replies: 10
    Last Post: 05-18-2006, 11:23 PM
  4. Developing database management software
    By jdm in forum C++ Programming
    Replies: 4
    Last Post: 06-15-2004, 04:06 PM
  5. Making a Simple Database System
    By Speedy5 in forum C++ Programming
    Replies: 1
    Last Post: 03-14-2003, 10:17 PM