Home > Back-end >  The elder brothers you compress the access?
The elder brothers you compress the access?

Time:10-13

???????????????????????????????????

CodePudding user response:

Close the database connection, and then:
 BOOL __stdcall CrnCompactMDB (LPCSTR lpMdbFile, LPCSTR lpOldPwd, LPCSTR lpNewPwd) 
{
Char szPath [MAX_PATH]={0};
: : GetTempPathA (MAX_PATH, szPath);
Char szTmpFile [MAX_PATH]={0};
: : GetTempFileNameA (szPath, "CCM," 0, szTmpFile);

Char szOldProvide [512]={0}, szNewProvide [512]={0};

Sprintf (szOldProvide,
"The Provider=Microsoft. Jet. The OLEDB. 4.0;"
"Data Source=% s."
"Jet OLEDB: Database Password=% s",
LpMdbFile lpOldPwd);

Sprintf (szNewProvide,
"The Provider=Microsoft. Jet. The OLEDB. 4.0;"
"Data Source=% s."
"Jet OLEDB: Database Password=% s",
SzTmpFile lpNewPwd);

BOOL bResult=FALSE;

The Variant vAdoObj;

Try
{
If (: : PathFileExistsA (szTmpFile))
: : DeleteFileA (szTmpFile);

VAdoObj=the Variant: : CreateObject (" JRO. JetEngine ");
VAdoObj. OleProcedure (" CompactDatabase WideString (szOldProvide), WideString (szNewProvide));

If (: : PathFileExistsA (lpMdbFile))
: : DeleteFileA (lpMdbFile);

: : MoveFileA (szTmpFile lpMdbFile);

BResult=TRUE;
}
__finally
{
VAdoObj. The Clear ();
VAdoObj=Unassigned;
}

Return bResult;
}
  • Related