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

2
  • 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 Commented Sep 20, 2016 at 23:09
  • @Plutonix thanks, I posted the working solution with double Try - Using blocks Commented Sep 21, 2016 at 10:20

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

4 Comments

thanks but didn't work. Something wrong with the sintaxis. I will post the solution.
@fedeteka the only thing wrong is an extra trailing parens (edit: was wrong)
@Plutonix. Right, thanks. Also I think Version=3;" works the same as Version=3" without the last semicolon
there are a number of other cool things you can add to the connection string, so it can be a good idea to leave the trailing delimiter

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.