压缩数据库

时间:2013-06-26 21:17:42

标签: database vb.net ms-access-2010

我正在尝试压缩我的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:\Forte\Fortedb.accdb", "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\C:\Forte\Compactdb.accdb")


    'Original (not compacted database is deleted)
    System.IO.File.Delete("C:\Program Files\VSoft\AppMiss\NewAppDB.mdb")

    'Compacted database is renamed to the original databas's name. 
    Rename("C:\Forte\Compactdb.accdb", "C:\Forte\Fortedb.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.accdb” ”。找不到文件'\ phipnasw01 \ users-hip $ \ cerns1 \ My Documents \ Visual Studio 2010 \ Projects \ Forte Data Gatherer \ Forte Data Gatherer \ Example1.accdb'。 Forte Data Gatherer

1 个答案:

答案 0 :(得分:1)

当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:\Forte\Fortedb.accdb"
    Dim compact = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Forte\Compactdb.accdb"
    JRO.CompactDatabase(source, compact)

    'Original (not compacted database is deleted)
    System.IO.File.Delete("C:\Forte\Fortedb.accdb")

    'Compacted database is renamed to the original databas's name. 
    File.Move("C:\Forte\Compactdb.accdb", "C:\Forte\Fortedb.accdb")

    'User notification
    MsgBox("The database was compacted successfully")

End Sub