in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

Database file isn't copying over?

Last post 09-14-2009 11:51 AM by andyd273. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 09-14-2009 9:39 AM

    Database file isn't copying over?

     I'm playing around a bit with trying to get a sqlite database to open and display in a mobile application, and I'm having some trouble getting it going.

    From what I can tell, the file isn't being copied like it's supposed to. When I go into file explorer on the simulator,  there is a file, but its getting created when the program calls connection.open, and not getting copied from the project directory. It has a size of 0.

    I have the file pgt.db3 set to copy always.

    here's the code:

    Imports System.Data.SQLite

    Public Class Form1

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim conn As New SQLiteConnection("Data Source=|DataDirectory|pgt.db3;")
            conn.Open()

            Dim cmd As New SQLiteCommand("Select * From PGT", conn)
            Dim reader As SQLiteDataReader
            reader = cmd.ExecuteReader  ' table not found error happens here, the code after this has not been tested in any way.

            Dim lItm As New ListViewItem
            Do While reader.Read
                lItm.Text = reader.Item(0).ToString & " - " & reader.Item(1).ToString
                ListView1.Items.Add(lItm)
                reader.NextResult()
            Loop
        End Sub
    End Class

    Is there anything else that I'm missing?

  • 09-14-2009 10:07 AM In reply to

    Re: Database file isn't copying over?

    Well, the 0 file size occurs because when you try to open a connection to a database that is not there, one is created at that location.

     

    It sounds like you need to set the build property of the database in your project to Content and then Copy if Newer.

     

    It appears that the database isn't getting deployed with the application.

  • 09-14-2009 11:51 AM In reply to

    Re: Database file isn't copying over?

     That appears to have done it!

     I knew there had to be an easier way to do it...

    Now I just have to find out if I need to password protect my database file to make it so that it can't be opened outside of the program, or can I somehow encrypt/hide it so that it's just not visible...

     Thanks a lot for the quick reply

Page 1 of 1 (3 items)
Powered by Community Server (Commercial Edition), by Telligent Systems