1

New to wpf and sqlite. I just want an internal database for my project. I want this project to be able to used by others so I cannot use mysql as a database. So I search for internal databases and decided to try sqlite. Im finding tutorial but they are really confusing. I'm familiar in database I know the queries but now I just need to know what are the necessary things to setup to start the connection between WPF and sqlite. Below is my code(I create a different class for my sqlite connection):

 sqlite class

 using System.Data.SQLite;
 namespace StartMyApps
 {
     class StartMyAppDb_sqlite
     {
       public SQLiteConnection myConn;
       public SQLiteCommand myComm;
       public SQLiteDataReader myReader;

       public void openConnection(string query)
       {
         myConn = new SQLiteConnection("Data Source=StartMyApplication.sqlite;Version=3;");
         myConn.Open();
         myComm = new SQLiteCommand(query, myConn);
         myComm.ExecuteNonQuery();
         myReader = myComm.ExecuteReader();
       }      
    }
 }

 Main class (has a button to trigger the connection and will pass a query)

   private void hide_btn_Click(object sender, RoutedEventArgs e)
    {
        sqliteDB.openConnection("select *from application where app_id='1' and app_name='chrome.exe';");

        bool hasAccount = false;
        while (sqliteDB.myReader.Read())
        {
            hasAccount = true;
        }

        if (hasAccount == false)
        {
            MessageBox.Show("Logged in");
        }

        else if (hasAccount == true)
        {
            MessageBox.Show("Username invalid");
        }
    }

With this code I got an error says

"An unhandled exception of type 'System.DllNotFoundException' occurred in System.Data.SQLite.dll Additional information: Unable to load DLL 'SQLite.Interop.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"

Please help. Any help will be much appreciated THANKS!

2 Answers 2

1

I think this is what your looking for: Unable to load DLL 'SQLite.Interop.dll'

Assuming you have:

  • SQLite installed (correct version for windows)

  • Appropriate references

Sign up to request clarification or add additional context in comments.

Comments

0

Follow below steps:

  • Add 2 folders in the project and name it x64 and x86.
  • Add SQLite.interop.dll for x64 and x86 respectively(google for the same)
  • In SQLite.interop.dll properties, set "Build Action" --> Content and "Copy to Output directory" -> Copy Always/Copy if newer.

2 Comments

I don't have sqlite.interop.dll. Where is the right file in the internet to download?
Check the package directory when you install from Nuget. It will have the SQLite.interop.dll

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.