access| Data | database | compression
In fact, the implementation of the other language has been very clear, I just use PB to organize a bit, to facilitate the need for this function of the students.
The method function is given directly below:
1, the Declaration of external functions, to take the system's temporary path.
FUNCTION ULONG GetTempPath (ULONG nbufferlength,ref string lpbuffer)
LIBRARY "Kernel32.dll" ALIAS for "Gettemppatha"
2, the Core method:
Global type Gf_compactandrepairaccessdb from Function_objectend type forward Prototypesglobal function integer gf_ Compactandrepairaccessdb (string as_mdb) end Prototypesglobal function integer gf_compactandrepairaccessdb (string as_ MDB)//Check that the database file exists if not fileexists (As_mdb) then return-1//create a temporary file name string Ls_tmpfilels_tmpfile =space (255) GetTempPath (255,ls_tmpfile) ls_tmpfile+= "Temp.mdb"//creating Dbengineinteger resultoleobject Ole_dbengineole_dbengine = Create OLEObject result =ole_dbengine.connecttonewobject ("JRO. JetEngine ")//Create failure if result<>0 then return result//compressed database file string DBEngine = ' Sprovider via provider= Microsoft.Jet.OLEDB.4.0 ' string soldmdb,snewmdbsoldmdb = Sprovider + ' data source= ' + As_mdbsnewmdb = sprovider + ' data Source= ' + ls_tmpfileole_dbengine.compactdatabase (Soldmdb, Snewmdb) Destroy ole_dbengine//copy just compressed the staging database file to its original location FileCopy (ls_tmpfile,as_mdb,true)//delete temporary file Filedelete (ls_tmpfile) return 0end function
It should be noted that in the process of compressing and repairing the database, there can be no other operation to open the database, otherwise the operation will fail, so please shut down the connection to the database, otherwise the execution will be an error.
In addition, this function has been modified to achieve the function of backing up the database, compared to simpler, here is not provided.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.