Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 350
Ninad Avasare Avatar asked Feb 04 '26 17:02

Ninad Avasare


1 Answers

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).

like image 118
JRL Avatar answered Feb 06 '26 07:02

JRL



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!