PB compression and finishing Access database file (MDB)

xiaoxiao2021-03-06  42

In fact, it is very clear that the language is very clear. I just sort out in PB, and I need a classmate that needs this feature.

The method function is given directly below:

1. Apply an external function to take the temporary path of the system.

Function Ulong GetTemppath (Ulong NBufferlength, Ref String Lpbuffer) library "kernel32.dll" alias for "getTemppatha"

2, core method:

Global Type GF_CompactandRepairaccessDB from Function_Object

End Type

Forward Prototypes

GLOBAL FUNCTION INTEGER GF_COMPACTANDREPAIRACCESSDB (String As_MDB)

End protoypes

Global Function Integer GF_CompactandRepairaccessDB (String as_MDB);

/ / Check if the database file exists

IF not fileexists (as_mdb) THEN RETURN -1

// Create a temporary file name

String ls_tmpfile

LS_TMPFILE = Space (255)

GetTemppath (255, LS_TMPFILE)

LS_TMPFILE = "Temp.mdb"

// Create DBENGINE

INTEGER Result

OleObject ole_dbengine

OLE_DBENGINE = CREATE OLEOBJECT

Result = ole_dbengine.connecttonewObject ("jro.jetEngine")

// Creating a failure

If Result <> 0 THEN RETURN Result

// Compress database files through DBENGINE

String sprovider = 'provider = microsoft.jet.Oledb.4.0;'

String soldmdb, SNEWMDB

SOLDMDB = SPROVIDER 'DATA SOURCE =' as_mdb

SNEWMDB = SPROVIDER DATA SOURCE = ' LS_TMPFILE

OLE_DBENGINE.COMPACTDATABASE (SOLDMDB, SNEWMDB)

Destroy ole_dbengine

// Copying just compressed over the temporary database file to the original position

FileCopy (Ls_TMPFILE, AS_MDB, TRUE)

/ / Delete temporary files

FileDelete (ls_tmpfile)

Return 0

END FUNCTION

3, call method

GF_compactandrepairaccessDB ("e: /eno/collect.mdb")

It should be noted that in the process of compressing and repairing the database, there is no other operation to open the database, otherwise the operation will fail, so turn off the connection to the database, otherwise the execution will report an error.

In addition, this function can be modified, the function of the backup database can be implemented, and it is more simple, it is not available here.

转载请注明原文地址:https://www.9cbs.com/read-51415.html

New Post(0)