首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用VistaDB进行DB备份?

如何使用VistaDB进行DB备份?
EN

Stack Overflow用户
提问于 2015-04-05 22:00:01
回答 2查看 177关注 0票数 0

我试图用VistaDB对数据库进行XML导出。不巧的是,我迷路了。

到目前为止,这是我的代码:

代码语言:javascript
复制
    Dim instance As IVistaDBDatabase
    Dim value As System.Int64

    SaveFileDialog2.InitialDirectory = "C:\"
    Select Case SaveFileDialog2.ShowDialog()
        Case Windows.Forms.DialogResult.OK
            Try
                instance.ExportXml(SaveFileDialog2.FileName, VistaDBXmlWriteMode.All)
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
    End Select

我得到的只是对象没有设置为对象的实例(或类似的东西)。

有人能提供这样的指导吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-04-11 18:30:52

我从一个旧的代码包中找到了答案。以下是正确的代码:

代码语言:javascript
复制
    Dim vdbDatabase As IVistaDBDatabase = Nothing
    Dim filenameDB As String = SaveFileDialog2.FileName
    Dim filenameXML As String = SaveFileDialog2.FileName

    Select Case SaveFileDialog2.ShowDialog()
        Case System.Windows.Forms.DialogResult.OK
            Try

                ' Call the method that will open the connection to the database and return an open IVistaDBDatabase object for the database to us
                vdbDatabase = DDA.VistaDBEngine.Connections.OpenDDA.OpenDatabase("C:\Ledger.vdb5", VistaDBDatabaseOpenMode.NonexclusiveReadOnly, Nothing)


                ' Clear the XML Transfer List - this is the list used by the Import/Export methods
                vdbDatabase.ClearXmlTransferList()

                ' Loop through the tables in the database and add them to the XmlTransferList
                For Each tableName As String In vdbDatabase.GetTableNames()
                    vdbDatabase.AddToXmlTransferList(tableName)
                Next


                ' Call the ExportXML method with the name of the XML      file and the WriteMode value indicating what to Export
                vdbDatabase.ExportXml(filenameXML, VistaDBXmlWriteMode.All)

                ' If the database is open - close it
                If Not vdbDatabase.IsClosed Then
                    vdbDatabase.Close()
                End If
                MsgBox("Database Export complete.", MsgBoxStyle.Information)
            Catch ex As Exception
                WriteErrorEvent("Error exporting Database in addin", ex)
                MsgBox("An error occured attempting to export the Database. Error Message:" & vbCrLf & vbCrLf & ex.ToString, MsgBoxStyle.Exclamation)
            Finally
                ' If we have a vdbDatabase object               
                If Not (vdbDatabase Is Nothing) Then
                    ' If it is open, close it
                    If Not vdbDatabase.IsClosed Then
                        vdbDatabase.Close()
                    End If

                    ' Dispose of the object
                    vdbDatabase.Dispose()
                End If
            End Try
    End Select
票数 0
EN

Stack Overflow用户

发布于 2019-07-22 22:17:40

有点晚了,但是我对您的代码做了一个小小的更改,这样您就可以看到备份的确切时间了。

代码语言:javascript
复制
    Dim vdbDatabase As IVistaDBDatabase = Nothing
    Dim filenamedb As String = vdbDatabase
    Dim filenameXML As String = "MyDataBaseName_" + Now.ToString("dd-MM-yyyy_hh-mm-ss") + ".Xml"
    Dim path As String
    path = System.IO.Path.GetFullPath(filenameXML)

    Try
   vdbDatabase = DDA.VistaDBEngine.Connections.OpenDDA.OpenDatabase("DataDirectory|MyDataBase.vdb5", VistaDBDatabaseOpenMode.NonexclusiveReadOnly, Nothing)
vdbDatabase.ClearXmlTransferList()

        For Each tableName As String In vdbDatabase.GetTableNames()
            vdbDatabase.AddToXmlTransferList(tableName)
        Next

        vdbDatabase.ExportXml(filenameXML, VistaDBXmlWriteMode.All)

        If Not vdbDatabase.IsClosed Then
            vdbDatabase.Close()
        End If

        MsgBox("Backup is in " + path, MsgBoxStyle.Information)

    Catch ex As Exception
        MsgBox("An error occured attempting to export the Database. Error Message:" & vbCrLf & vbCrLf & ex.ToString, MsgBoxStyle.Exclamation)
    Finally

        If Not (vdbDatabase Is Nothing) Then
            If Not vdbDatabase.IsClosed Then
                vdbDatabase.Close()
            End If               
            vdbDatabase.Dispose()
        End If
    End Try
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29462700

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档