0

I am currently looking to compact and repair my mdb file (while i close my infopath form which makes the connection to the mdb file using the below code). I currently use the connection parameters as mentioned below. It would be really helpful if someone sheds some light on how this can be achieved in this scenario. JavaScript Function:

function GetConnection(){
_dbConn = new ActiveXObject("ADODB.Connection");
var databaseName = "test.mdb";
var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=xxxx;DataSource=c:\\test\\" + databaseName;
_dbConn.Open(strConn);
return _dbConn;
}

Appreciate your help! Thanks!

4

1 回答 1

1

只有 Access.Application 和 DAO.DBEngine 可以压缩 DB

Sub CompactDatabase(SrcName As String, DstName As String, [DstLocale], [Options], [SrcLocale])
    Member of DAO.DBEngine

Function CompactRepair(SourceFile As String, DestinationFile As String, [LogFile As Boolean = False]) As Boolean
    Member of Access.Application

所以试试这样的想法:

var Access;
var fso;

fso = new ActiveXObject("Scripting.FileSystemObject")
Access = new ActiveXObject("Access.Application");

fso.DeleteFile("c:\test\campactAndrepared.mdb", true);
Access.CompactRepair("c:\test\test.mdb", "c:\test\campactAndrepared.mdb", LogFile)

fso.DeleteFile("c:\test\test.bak", true);
fso.MoveFile "c:\test\test.mdb" , "c:\test\test.bak"

fso.DeleteFile("c:\test\test.mdb", true);
fso.MoveFile "c:\test\campactAndrepared.mdb" , "c:\test\test.mdb"
于 2013-10-15T18:44:39.703 回答