简体   繁体   中英

Using SQLite with C# winforms

I am trying to use SQLITE library with winforms solution, but its throwing an odd error saying :

" Could not load file or assembly 'System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139"

here is snippet code:

 internal string GetUserAppPath()
        {
            string dir = configure.appDir();
            try
            {
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                string dbPath = configure.dbFile();

                if (!File.Exists(dbPath))
                {
                    SQLiteConnection.CreateFile(dbPath);
                    SQLiteConnection cn = new SQLiteConnection("Data Source=" + dbPath);
                    SQLiteCommand scriptcommand = new SQLiteCommand(cn);


                    scriptcommand.CommandText = CustomSolution.Properties.Resources.DatabaseScript;

                    cn.Open();
                    scriptcommand.ExecuteNonQuery();
                    cn.Close();

                }
                DBfildir = "Data Source=" + dbPath;
            }
            catch (System.Exception ex)
            {
                //MessageBox.Show(x.Message);

            }
            return dir;
        }

Cant comment yet:

you can install them through nuget:

PM> Install-Package System.Data.SQLite

use the -Version 1.0.66 to specify a specific version eg 1.0.66

Just a few more question to understand your environment:

  • Did you add/install the SQLite package to your solution?
  • are the compiled dll's copied to your output folder when building?
  • double check your project refrences to make sure they are not marked as missing?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM