WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Access

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Repair MDB


Question:

Is there a way to repair a MDB via Winbatch. I have got some command for compacting an MDB and I think the same should be possible for repair like:

henv = __Database_Init()
If henv == -1 Then Return -1
hdbc = __Database_InitSQL(henv)
If hdbc < 0 Then Return -2

ret=qConfigData(2, "Microsoft Access Driver (*.mdb)", "COMPACT_DB=%db_nam% %db_nam% General", @FALSE)
qFreeConnect(hdbc)
qFreeEnv(henv)

Answer:

If you have Access installed (not just the Driver) you can use
cMDB = "c:\MY.MDB" ;Full path/name of access db
cBkup = "c:\MYBCKUP.MDB" ; Backup file name
oDB = CreateObject("Access.Application")
oDB.CompactRepair(::LogFile=@TRUE,SourceFile=cMDB,DestinationFile=cBkup)
oDB=0
If FileExist(cBkup)
   FileCopy(cBkup,cMDB,@FALSE)
   FileDelete(cBkup)
EndIf
I would hold off on the FileDelete(cBkup) unil I was sure things worked as planned. NOTE: the Access file must not be opened on the PC.
Article ID:   W17142
File Created: 2007:07:03:14:28:28
Last Updated: 2007:07:03:14:28:28