我正在尝试压缩我的Microsoft Access 2010数据库。我正在使用VS 2010。我似乎无法让压实机工作。我尝试了几种方法,得到了不同的错误消息。这是我现在拥有的代码。
Private Sub Compactdb()
Dim JRO As JRO.JetEngine
JRO = New JRO.JetEngine
'The first source is the original, the second is the compacted database under an other name.
JRO.CompactDatabase("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:ForteFortedb.accdb", "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:ForteCompactdb.accdb")
'Original (not compacted database is deleted)
System.IO.File.Delete("C:Program FilesVSoftAppMissNewAppDB.mdb")
'Compacted database is renamed to the original databas's name.
Rename("C:ForteCompactdb.accdb", "C:ForteFortedb.accdb")
'User notification
MsgBox("The database was compacted successfully")
End Sub
我现在得到的错误是
错误1无法将文件"\phipnasw01\users hip$\cerns1\My Documents\Visual Studio 2010\Projects\Forte Data Gatherer\Forte Data Gatherer\Example1.accdb"复制到"bin\Debug\Example1.ccdb"。找不到文件"\phipnasw01 \users ship$\carns1\My Documents\Visual Studio 2010\Projects\Forte Data Gatherir\Forte Data.accdb".Forte Data Gather
当VS DEBUG/RELEASE会话启动时,IDE会尝试将该文件从项目文件夹复制到输出目录(通常为BIN\DEBUG)。由于某些原因,IDE无法找到文件或路径,因此无法将其复制到输出目录。
这不是编程错误,而是项目文件的配置。
这个副本似乎与您显示的代码无关,因此,您可以将属性Copy to Output directory
设置为Never Copy
相反,关于上面的代码,您在文件名上犯了一些错误
Private Sub Compactdb()
Dim JRO As JRO.JetEngine
JRO = New JRO.JetEngine
Dim source = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:ForteFortedb.accdb"
Dim compact = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:ForteCompactdb.accdb"
JRO.CompactDatabase(source, compact)
'Original (not compacted database is deleted)
System.IO.File.Delete("C:ForteFortedb.accdb")
'Compacted database is renamed to the original databas's name.
File.Move("C:ForteCompactdb.accdb", "C:ForteFortedb.accdb")
'User notification
MsgBox("The database was compacted successfully")
End Sub