Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2005

    Unanswered: Using ODBC in C/C++ for Compact and Repair MS Access DB

    Is it possible using plain C to compact and repair a MS Access Database through ODBC?

    I'm trying the following code, found it in the WEB:

    void CompactAndRepairDB ()
    	RETCODE retcode;
    	int     subscrp;
    	CHAR szDriver[]			= "Microsoft Access Driver (*.mdb)";
    	CHAR *szAttributes2[]	=
    			// Create the original .mdb file.
    			// Compact the file.
    			"COMPACT_DB=db.mdb db2.mdb General\0\0"};
    	for (subscrp = 0; subscrp <= ((sizeof szAttributes2 / sizeof(UCHAR *)) - 1); subscrp++)
    		retcode = SQLConfigDataSource (NULL, ODBC_ADD_DSN, szDriver, szAttributes2[subscrp]);
    		if (retcode != TRUE)
    			for(int i=1;i<=8;i++)
    				DWORD dwcode = NULL;
    				WORD wlen = 0;
    				char szerr[SQL_MAX_MESSAGE_LENGTH] = {0};
    				if (SQLInstallerError((WORD)i, &dwcode, szerr, SQL_MAX_MESSAGE_LENGTH-1, &wlen) == SQL_SUCCESS)
    					printf ("Code: %u %s\n",dwcode,szerr);
    After creating the new compacted file I copy it over the old file.

    Though when I run the compacting program I get the following error:

    Driver's ConfigDSN, ConfigDriver, or ConfigTranslator failed.
    I'm not using an ODBC datasource, only using filenames.

    Thanks in advance,

  2. #2
    Join Date
    Feb 2004
    In front of the computer
    Provided Answers: 54
    I suspect that you'd be a lot better off using DAO than trying to do it using ODBC.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts