If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Other > Using ODBC in C/C++ for Compact and Repair MS Access DB

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-24-06, 13:57
anfernius anfernius is offline
Registered User
 
Join Date: Nov 2005
Posts: 1
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:

Code:
void CompactAndRepairDB ()
{
	RETCODE retcode;
	int     subscrp;

	CHAR szDriver[]			= "Microsoft Access Driver (*.mdb)";
	CHAR *szAttributes2[]	=
			// Create the original .mdb file.
			{"REPAIR_DB=db.mdb\0\0",
			// 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:

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

Thanks in advance,
Reply With Quote
  #2 (permalink)  
Old 02-01-06, 18:33
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,613
I suspect that you'd be a lot better off using DAO than trying to do it using ODBC.

-PatP
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On