如何使用JavaScript代码压缩和修复Access MDB文件?

时间:2013-10-15 16:12:33

标签: javascript ms-access infopath adodb

我目前正在寻找压缩和修复我的mdb文件(当我关闭我的infopath表单时,使用下面的代码连接到mdb文件)。我目前使用如下所述的连接参数。如果有人了解如何在这种情况下实现这一点,那将会非常有帮助。 JavaScript函数:

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;
}

感谢您的帮助!谢谢!

1 个答案:

答案 0 :(得分:1)

只有Access.Application和DAO.DBEngine可以压缩数据库

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"