Cant get SQLite to work with in my plugin, Revit 2024

Cant get SQLite to work with in my plugin, Revit 2024

Gilles.Lagrilliere
Advocate Advocate
206 Views
3 Replies
Message 1 of 4

Cant get SQLite to work with in my plugin, Revit 2024

Gilles.Lagrilliere
Advocate
Advocate

Hello Everyone,

 

I have an updater and I want to use SQLite as my database. But everytime try to test my code, I get this error: System.DllNotFoundException: 'Unable to load DLL 'e_sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E)'

 

I can't find this DLL anywhere.

 

I get the error on this line:  using (SQLiteConnection connection = new SQLiteConnection($"Data Source={dbPath};Version=3;"))

 

Here is my code:

 

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Data.SQLite;

namespace TestSqlite
{
    public class Updater : IUpdater
    {
        private readonly Guid id = Guid.NewGuid();
        private readonly UpdaterId updaterId;
        private readonly string dbPath = @"C:\Users\GillesLagrilliere\OneDrive - Talenco BVBA\Desktop\test.db";
        public Updater(AddInId addInId)
        {
            this.updaterId = new UpdaterId(addInId, id);
        }
        public void Execute(UpdaterData data)
        {
            TaskDialog.Show("TestSqlite", "Updater Executed");

            try
            {
                using (SQLiteConnection connection = new SQLiteConnection($"Data Source={dbPath};Version=3;"))
                {
                    connection.Open();
                    string sql = "CREATE TABLE IF NOT EXISTS Test (Id INTEGER PRIMARY KEY, Name TEXT)";
                    using (SQLiteCommand command = new SQLiteCommand(sql, connection))
                    {
                        command.ExecuteNonQuery();
                    }
                    sql = "INSERT INTO Test (Name) VALUES ('Revit Updater Triggered')";
                    using (SQLiteCommand command = new SQLiteCommand(sql, connection))
                    {
                        command.ExecuteNonQuery();
                    }
                    connection.Close();
                }
            }
            catch (Exception)
            {

                throw;
            }
        }

 

Any help is welcome!

Gilles Lagrilliere 

0 Likes
207 Views
3 Replies
Replies (3)
Message 2 of 4

Charles.Piro
Advisor
Advisor

Hi,

 

you can resolve this issue by installing the SQLite packages and copy the dll files to the addin folder.

To begin, install the packages : 

 

Install-Package Microsoft.Data.Sqlite
Install-Package SQLitePCLRaw.bundle_e_sqlite3

 

Once your solution is compiled, the dependency assemblies will be located in your debug folder and you can copy them to your addin folder.

 

😉



PIRO Charles
Developer

PIRO CIE
Linkedin


Message 3 of 4

Gilles.Lagrilliere
Advocate
Advocate

Hi

 

I tried your solution but now I get this error: 

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Exception: Library e_sqlite3 not found
plat: win
suffix: DLL
possibilities (3):
1) C:\Program Files\Autodesk\Revit 2024\runtimes\win-x64\native\e_sqlite3.dll
2) C:\Program Files\Autodesk\Revit 2024\e_sqlite3.dll
3) C:/Program%20Files/Autodesk/Revit%202024/e_sqlite3.dll
win TryLoad: C:\Program Files\Autodesk\Revit 2024\runtimes\win-x64\native\e_sqlite3.dll
thrown: System.ComponentModel.Win32Exception (0x80004005): The specified module could not be found
at SQLitePCL.NativeLibrary.TryLoad(String name, Loader plat, Action`1 log, IntPtr& h)
win TryLoad: C:\Program Files\Autodesk\Revit 2024\e_sqlite3.dll
thrown: System.ComponentModel.Win32Exception (0x80004005): The specified module could not be found
at SQLitePCL.NativeLibrary.TryLoad(String name, Loader plat, Action`1 log, IntPtr& h)
win TryLoad: C:/Program%20Files/Autodesk/Revit%202024/e_sqlite3.dll
thrown: System.ComponentModel.Win32Exception (0x80004005): The specified module could not be found
at SQLitePCL.NativeLibrary.TryLoad(String name, Loader plat, Action`1 log, IntPtr& h)
NOT FOUND

at SQLitePCL.NativeLibrary.Load(String libraryName, Assembly assy, Int32 flags)
at SQLitePCL.Batteries_V2.MakeDynamic(String name, Int32 flags)
at SQLitePCL.Batteries_V2.DoDynamic_cdecl(String name, Int32 flags)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at Microsoft.Data.Sqlite.SqliteConnection..cctor()

 

It still can't find e_sqlite3.dll.

0 Likes
Message 4 of 4

Charles.Piro
Advisor
Advisor

Hi,

 

sorry to hear that. I searched and found the e_sqlite3.dll file inside my C:/Microsoft Visual Studio folder. For me, the path is : C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Microsoft\Copilot\Conversations.Service\runtimes\win-x64\native

but I'm not sure if it's the same for you. To help you, I've joined the assembly.

 

😉



PIRO Charles
Developer

PIRO CIE
Linkedin


0 Likes