fedeteka fedeteka - 2 months ago 40
Vb.net Question

Backup SQLite database with VB.Net

I don't find documentation for VB.NET

Trying to adapt the code of the answer on Sqlite Online Backup Using System.Data.Sqlite

The code from @Elias is:

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);
}


and my code looks like:

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 marks on red "Null" is not declared and I donĀ“t have any clue about how to solve the error. I think is the "callback" what is wrong

enter image description here

Answer

Here is the direct translation of that C# code:

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