1

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

Community
  • 1
  • 1
fedeteka
  • 943
  • 1
  • 14
  • 33
  • 1
    In VB null is `Nothing`. Also, connections are one of those things that should be disposed of when you are done with it. That is why the c# version has both wrapped in `Using` / `using` blocks – Ňɏssa Pøngjǣrdenlarp Sep 20 '16 at 23:09
  • @Plutonix thanks, I posted the working solution with double Try - Using blocks – fedeteka Sep 21 '16 at 10:20

1 Answers1

1

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
Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
jmcilhinney
  • 50,448
  • 5
  • 26
  • 46