delphisqlitedelphi-xe3

Getting sqlite3.dll not found error with Delphi


I am getting sqlite3.dll not found error at Delphi app. I already have sqlite3.dll file on my PC located at E://sqlite-dll-win32-x86-3071700

My source is as follows

procedure TForm2.Button1Click(Sender: TObject);
var
    Results: TDataSet;
begin
    SQLConnection1.Params.Add('Database=E://empn.s3db');
    SQLConnection1.LibraryName := 'E://sqlite-dll-win32-x86-3071700/sqlite3.dll';
    try
        SQLConnection1.Connected := true;
        SQLMonitor1.Active := True;

        SQLConnection1.Execute('Selct * from usergroup', nil, Results)

    finally

    end;
end;

As mentioned in above code already pointed out path to the library by

SQLConnection1.LibraryName := 'E://sqlite-dll-win32-x86-3071700/sqlite3.dll';

But still I do get error like sqlite3.dll not found. how to troubleshoot this error?


Solution

  • A small note

    Beginning with Delphi XE3, LibraryName is obsolete.

    In older Delphi versions, LibraryName indicated the "dbExpress library associated with the driver" (e.g. dbxfb.dll for Firebird), while VendorLib indicated the "library supplied by the database vendor to support client-side use of the database" (e.g. fbclient.dll/fbembed.dll for Firebird, equivalent to Sqlite's sqlite3.dll).


    Embarcadero's Sqlite dbExpress driver

    In you are on Windows, this driver uses delayed loading of sqlite3.dll. Something like:

    function sqlite3_open_v2; external 'sqlite3.dll' delayed;
    

    so the dll is loaded with LoadLibrary and the standard search strategy to find modules applies (first the process directory, then the usual path list).

    However this stategy can be altered by using SetDllDirectory.

    So you have to put sqlite3.dll accessible thru your path or try the following hack:

    (beware that this will interfere with other code that have used SetDllDirectory; see David Heffernan's comment)

    SetDllDirectory('E:\sqlite-dll-win32-x86-3071700');
    try
      SQLConnection1.Open;
    finally
      SetDllDirectory(''); // restore default search order
    end;
    

    Warning: Also make sure that you are not mixing 32 and 64 bits modules (i.e. 32 bit exe and 64 bit dll or vice versa).