为什么我不能使用“CompactDatabase”在DAO.DBEngine.36中使用VBscript? [英] Why can't I use "CompactDatabase" in DAO.DBEngine.36 using VBscript?

查看:477
本文介绍了为什么我不能使用“CompactDatabase”在DAO.DBEngine.36中使用VBscript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想要的代码是:



设置acc2007 = CreateObject(DAO.DBEngine.36)
acc2007.CompactDatabaseC:\test.accdb,C: \\ test2.accdb,Nothing,Nothing,; pwd = test
设置acc2007 =无任何

当我从32位cmd.exe运行cscript test.vbs的三行时出现此错误:



C:\test .vbs(10,1)DAO.DbEngine:无法识别的数据库格式C:\test.accdb。



2007,当我打开它通过双击图标我键入密码测试,然后我打开正常。它在顶部说Access 2007,所以它具有正确的格式。



这里是我想使用的功能的文档: http://msdn.microsoft.com/en-us/library/bb220986.aspx



对象DAO.DBEngine.36已成功创建,因为我没有在该行上得到任何错误。可能出错?

解决方案

DAO 3.6不支持新的ACCDB数据库格式。尝试使用DAO.DBEngine.120。



这是一个在我的系统上可用的示例。

  Dim objFSO 
Dim objEngine
Dim strLckFile
Dim strSrcName
Dim strDstName
Dim strPassword

strLckFile = C:\Access\webforums\foo.laccdb
strSrcName =C:\Access\webforums\foo.accdb
strDstName =C:\Access\webforums \compacted.accdb
strBackup =C:\Access\webforums\foobackup.accdb
strPassword =foo

设置objEngine = CreateObject DAO.DBEngine.120)

设置objFSO = CreateObject(Scripting.FileSystemObject)
如果不是(objFSO.FileExists(strLckFile))then
If(objFSO.FileExists (strBackup))然后
objFSO.DeleteFile strBackup
如果
结束if(objFSO.FileExists(strDstName))然后
objFSO.DeleteFile strDstName
结束如果
objFSO.CopyFile strSrcName,strBackup

dbVersion120 = 128
objEngine.CompactDatabase strSrcName,strDstName,,128,; pwd =& strPassword

objFSO.DeleteFile strSrcName
objFSO.MoveFile strDstName,strSrcName
End If'LckFile

注意:我决定在压缩之前备份我的数据库。最后,我删除原始(未压缩)数据库,并将压缩的数据库重命名为原始名称。



编辑:修改检查锁定文件;如果您对此不感兴趣,可以通过删除objFSO来简化这一操作。如果发现什么也不做。


I'm trying to make a small VBScript that compacts a MS Access 2007 database file.

The code I have is:

Set acc2007 = CreateObject("DAO.DBEngine.36")
acc2007.CompactDatabase "C:\test.accdb", "C:\test2.accdb", Nothing, Nothing, ";pwd=test"
Set acc2007 = Nothing

I'm getting this error when I run the three lines with "cscript test.vbs" from a 32-bit cmd.exe:

C:\test.vbs(10, 1) DAO.DbEngine: Unrecognized database format 'C:\test.accdb'.

The database was created with MS Access 2007, when I open it by double-clicking the icon I type the password "test" and then i opens normally. It says "Access 2007" at the top so it has the correct format.

Here's documentation of the function I'm trying to use: http://msdn.microsoft.com/en-us/library/bb220986.aspx

The object DAO.DBEngine.36 is created successfully since I'm not getting any errors on that line. What can be wrong?

解决方案

DAO 3.6 does not support the new ACCDB database format. Try DAO.DBEngine.120 instead.

Here is an example which works on my system.

Dim objFSO
Dim objEngine
Dim strLckFile
Dim strSrcName
Dim strDstName
Dim strPassword

strLckFile =  "C:\Access\webforums\foo.laccdb"
strSrcName =  "C:\Access\webforums\foo.accdb"
strDstName =  "C:\Access\webforums\compacted.accdb"
strBackup = "C:\Access\webforums\foobackup.accdb"
strPassword = "foo"

Set objEngine = CreateObject("DAO.DBEngine.120")

Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not (objFSO.FileExists(strLckFile)) Then
    If (objFSO.FileExists(strBackup)) Then
        objFSO.DeleteFile strBackup
    End If
    If (objFSO.FileExists(strDstName)) Then
        objFSO.DeleteFile strDstName
    End If
    objFSO.CopyFile strSrcName, strBackup

    ''dbVersion120 = 128 
    objEngine.CompactDatabase strSrcName, strDstName, , 128, ";pwd=" & strPassword

    objFSO.DeleteFile strSrcName
    objFSO.MoveFile strDstName, strSrcName
End If 'LckFile

Note: I decided to make a backup of my database before compact. At the end, I remove the original (uncompacted) database and rename the compacted one to the original name. If you're not interested in that, you could simplify this by removing the objFSO stuff.

Edit: Revised to check for lock file; if found do nothing.

这篇关于为什么我不能使用“CompactDatabase”在DAO.DBEngine.36中使用VBscript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆