0

I'm having a problem getting Sqlite to work in my c# irc bot.

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

namespace ModBot
{
class Database
{
    private SQLiteConnection myDB;
    private SQLiteCommand cmd;

    public Database()
    {
        InitializeDB();
    }

    private void InitializeDB()
    {
        if (File.Exists("ModBot.db"))
        {
            Console.WriteLine("HEYOOOOOOO");
            myDB = new SQLiteConnection("Data Source=ModBot.db;Version=3;");
            String sql = "CREATE TABLE IF NOT EXISTS twitch (id INTEGER PRIMARY KEY, user TEXT, currency INTEGER DEFAULT 0, subscriber INTEGER DEFAULT 0, btag TEXT DEFAULT null);";
            cmd = new SQLiteCommand(sql, myDB);
            cmd.ExecuteNonQuery();
        }
        else
        {
            Console.WriteLine("YOOHOOOOO");
            SQLiteConnection.CreateFile("ModBot.db");
            myDB = new SQLiteConnection("Data Source=ModBot.db;Version=3;");
            String sql = "CREATE TABLE IF NOT EXISTS twitch (id INTEGER PRIMARY KEY, user TEXT, currency INTEGER DEFAULT 0, subscriber INTEGER DEFAULT 0, btag TEXT DEFAULT null);";
            cmd = new SQLiteCommand(sql, myDB);
            cmd.ExecuteNonQuery();
        }
    }
}
}

I downloaded System.Data.Sqlite, and added it as a resource to my project. When I run the code, it throws a DllNotFound exception (Specifically: Unable to load DLL 'SQLite.Interop.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)) when it tries to make the actual connection.

Any ideas?

Keirathi
  • 397
  • 1
  • 5
  • 18
  • Are you sure you're targeting the right platform? http://stackoverflow.com/questions/4744293/unable-to-load-dll-sqlite3-the-specified-module-could-not-be-found-exceptio – wgraham May 30 '13 at 17:55
  • Did you paste it correctly? – AAlferez May 30 '13 at 17:57
  • @wgraham: I'm not sure how to change target platform with Visual C# 2010. I tried using both the x86 and x64 SQLite dll's, though. Same Error with either one. – Keirathi May 30 '13 at 18:03
  • @AnnArbor: I believe so. What doesn't look correct? – Keirathi May 30 '13 at 18:03
  • Did you added to the references? – AAlferez May 30 '13 at 18:06
  • (Disclaimer: this is my first program ever using an external resource dll). Yes, I think so. I hit "Add Resource", selected System.Data.SQLite.dll, and it shows up in the resources list. Also, it doesn't throw any compiler errors, only the runtime error. And, when I debug build the program, the DLL is copied into the /bin/debug/ folder alongside the exe. – Keirathi May 30 '13 at 18:12

1 Answers1

0
  1. Installing the RTM version of the Visual C++ runtime libraries works perfectly with System.Data.SQLite 1.0.74. So the SP1 version is not needed.

  2. The version of the C runtime installed with the .NET 4 runtime is the RTM version of msvcr100, but has the name msvcr100_clr0400.dll. With a copy of this renamed to msvcr100.dll, either in System32 or next to the System.Data.SQLite.dll, everything seems to work.

  3. It seems they've moved away from SxS deployment of the C runtime. So no more 'dependency' tag in the embedded manifest, and whatever the latest version is in System32 (or same directory as the .exe) will be loaded.

Some buddy asked a question on StackOverflow about these changes: Visual C++ 2010: Changes to MSVC runtime deployment (no more SxS with manifest).

This all means for the .NET 4 version you can deploy System.Data.SQLite.dll and msvcr100.dll in the same directory, which was not possible with the previous version of the runtime. For me that sorts out all my problems and you can move to the current versions of System.Data.SQLite.dll.

Community
  • 1
  • 1
  • Didn't seem to work for me, assuming I did what you were suggesting correctly. Went to C:\Windows\System32\, copied msvcr100_clr0400.dll, and put it into the same folder as the .exe, and renamed it to msvcr100.dll. – Keirathi May 30 '13 at 18:15