SQLite Forum

Visual Studio C# project SQLite Not working
Login

Visual Studio C# project SQLite Not working

(1) By John Watson (JohnSWatson) on 2021-03-07 08:44:33 [link] [source]

I am maintaining/building a Windows Forms application (family project) using Visual Studio Community 2019, AForge and SQLite.
The application has been working for over 3 years with frequent amendments and additions. 

For the latest change I created two user controls, both where owner draw listboxes  (drawing a colour background for each item. One of the controls was added to the form and worked fine, when trying to add the second control it fails with a message which says the SQLite.Interop.dll is not available or corrupted, if I try to place the control a second time VS deletes it from the project, after which every sqlite statement errors and there is no way to recover the project.
Which is why I created a minimum failing program, and it did fail.
What have I missed; any suggestions helped apricated? I need a disconnected, serverless database.
The only alternative I have found was not SQL, I started programming with PL1, I was there at the berth of SQL and way to old to learn new stuff.

1, created a User control that calls
 
        static public DataTable GetColours()
        {
            DataTable Colours = new DataTable();
            Colours.Columns.Add("colour_group_id", typeof(int));
            etc ...

            Colours.TableName = "ColourInGroups";

            SQLiteConnection objConn = new SQLiteConnection(DB_Connect_String());

            string sql = "SELECT ... ORDER BY sort_order;";

            SQLiteDataAdapter adapter = new SQLiteDataAdapter(sql, objConn);
            SQLiteCommandBuilder command = new SQLiteCommandBuilder(adapter);
            adapter.Fill(Colours);

            return Colours;
        }
        // END GetColours()

3. Installed the following NuGet packages
•	System.DataSQLite
•	System.DataSQLite.Core
•	System.DataSQLite.EF6
•	System.DataSQLite.Linq
In fact System.DataSQLite included the other three.

(2) By John Watson (JohnSWatson) on 2021-03-08 06:19:27 in reply to 1 [source]

Solved

User Control was programmed to load a listbox items list when the controls host-form loads.

What this means is. When you place the control on a form at design time the designer runs this code. It would seem to do it in unmanaged code and needs SQLite.Interop.dll, which is not available.

Solution. Method in the control asks it to initialise its data, this is called in the forms Activate event.