使用VB.Net备份SQLite数据库

时间:2016-09-20 22:44:40

标签: vb.net sqlite

我找不到VB.NET的文档

尝试在Sqlite Online Backup Using System.Data.Sqlite

上调整答案代码

来自@Elias的代码是:

using(var source = new SQLiteConnection("Data Source=ActiveDb.db; Version=3;"))
using(var destination = new SQLiteConnection("Data Source=BackupDb.db; Version=3;"))
{
source.Open();
destination.Open();
source.BackupDatabase(destination, "main", "main", -1, null, 0);
}

我的代码如下:

Dim conn = New SQLiteConnection("Data Source=MyBase.sqlite;Version=3;Password=myPassword;foreign keys=true")

Dim connbackup = New SQLiteConnection("Data Source=MyBaseBackup.sqlite; Version=3;Password=myPassword;foreign keys=true")

    Try
        Using (conn)

            conn.Open()
            connbackup.Open()

            conn.BackupDatabase(connbackup, "main", "main", -1, null, 0)

        End Using

    Catch ex As Exception
        MsgBox(ex.ToString())
    End Try

Visual Studio标记为红色“Null”未声明,我对如何解决错误没有任何线索。我认为是“回调”出了什么问题

enter image description here

1 个答案:

答案 0 :(得分:1)

以下是该C#代码的直接翻译:

Using source As New SQLiteConnection("Data Source=ActiveDb.db; Version=3;"),
      destination As New SQLiteConnection("Data Source=BackupDb.db; Version=3;")
    source.Open()
    destination.Open()
    source.BackupDatabase(destination, "main", "main", -1, Nothing, 0)
End Using