0

I just started to use SQLite. Doesn't seem to look like MySQL and SQL Server and MS Access that I use. I sought for several information online, nothing I could really find as well I decided to post here.

It connects well, and the libraries are present in the folder, but when I try to insert into the database, it throws an exception to the console.

My code looks like this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Data.SQLite;

namespace sqliteInsert
{
    class Program
    {
        static void Main(string[] args)
        {
            string constring = "Data Source=C:\\Users\\DornellPC\\Desktop\\people_db.db;Version=3;New=False;Compress=True;";

            using (SQLiteConnection con = new SQLiteConnection(constring))
            {
                try
                {
                    string sql = "insert into people_data (first_name,last_name,tel,email) values ('Jack','Darwin','0966358936','j_darwin@fsmail.net')";
                    con.Open();
                    Console.WriteLine("Connection open!");

                    using (SQLiteCommand cmd = new SQLiteCommand(sql,con))
                    {
                        cmd.ExecuteNonQuery();
                        Console.WriteLine("Success!");
                        Console.ReadLine();
                    }
                }
                catch(Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
        }
    }
}

and no information has been inserted into the database as it throws this exception:

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or ass embly 'System.Data.SQLite, Version=1.0.105.2, Culture=neutral, PublicKeyToken=db 937bc2d44ff139' or one of its dependencies. The system cannot find the file specified.

at sqliteInsert.Program.Main(String[] args)

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Thomas
  • 19
  • 2
  • Is there any `InnerException` ? – Felix D. Oct 10 '17 at 11:12
  • 1
    Possible duplicate of [Could not load file or assembly 'System.Data.SQLite'](https://stackoverflow.com/questions/1278929/could-not-load-file-or-assembly-system-data-sqlite) – Sinatr Oct 10 '17 at 11:12
  • 1
    So before the exception appears in the console, you see `"Connection open!"`? I would expect it to throw an exception on the `con.Open();` line. – C.Evenhuis Oct 10 '17 at 11:13
  • @FelixD., None i can see here. just this i pasted for your viewing – Thomas Oct 10 '17 at 11:14
  • @Thomas when debuggin and hover over `ex` check if `InnerException` is null or whethere there is more to it. Otherwise I would agree with @C. Evenhuis's comment. – Felix D. Oct 10 '17 at 11:16
  • Platform `Any CPU`? Did you install SQLite via NuGet or in a different way, manually perhaps? – LocEngineer Oct 10 '17 at 11:17
  • 3
    *"It connects well, and the libraries are present in the folder"* - both are false, it throw at connect and you more likely forgot to add `x64`/`x86` folders as well. – Sinatr Oct 10 '17 at 11:17
  • @LocEngineer i installed via Nuget – Thomas Oct 10 '17 at 11:18
  • @Sinatr i went thru this Properties -> Build and changd to x64, still gave same error – Thomas Oct 10 '17 at 11:19
  • You installed via Console, right? Uninstall, then re-install SQLite using the NuGet GUI (Tools=>NuGet=>Manage Packages). – LocEngineer Oct 10 '17 at 11:27
  • could you add `while(ex.InnerException != null){ ex = ex.InnerException; }` and then call `Console.WriteLine(ex.ToString());` in your `catch` block ? - see if that is showing you any more information on that error. – Felix D. Oct 10 '17 at 12:55
  • @FelixD., Now it doesnt show anything. – Thomas Oct 10 '17 at 12:58

0 Answers0