Recent

Author Topic: Unable to connect to sqllite  (Read 6604 times)

steveinalabama

  • New Member
  • *
  • Posts: 12
Unable to connect to sqllite
« on: June 22, 2021, 06:35:45 am »
I get an error message trying to set sqlconnection1.connected to true:
cannot load sqlite client library sjlite3.dll
I have 3 sqlite3.dll files on my computer, one put there by dbbrowser, one by a Delphi install, and 1 I copied to the folder containing the sqlite databasename.db file
all 3 files are of a size of a different number of bytes.

Can anyone tell me how to fix this?
Thank you.



Zvoni

  • Hero Member
  • *****
  • Posts: 627
Re: Unable to connect to sqllite
« Reply #1 on: June 22, 2021, 08:31:39 am »
put the dll into the same folder as the lazarus-exe
or assign the path in code
One System to rule them all, One IDE to find them,
One Code to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
People call me crazy, because i'm jumping out of perfectly fine aircraft

Awkward

  • Jr. Member
  • **
  • Posts: 83
Re: Unable to connect to sqllite
« Reply #2 on: June 22, 2021, 09:12:44 am »
and don't forget to check what your program and sqlite.dll is for same bitness, compiled for x86 or x64

steveinalabama

  • New Member
  • *
  • Posts: 12
Re: Unable to connect to sqllite
« Reply #3 on: June 23, 2021, 01:19:55 am »
I copied the sqlite3.dll into the lazarus folder and I it sort of worked.  In the IDE I changes the connected property to true and it did not fail. Fixed, I thought. But then I added a tsqlquery and it is in a different folder than Lazarus, so I copied the sqlite3.dll into the same folder as the database file. When I tried to open the query I got the same error message i was getting.

You mentioned to check the bitness matches. Isthere a way to tell how many bits a dll s configured for?
It may be that an older version of Delphi is 32 bits, the the file than contains sqlite3.dll is on the path. I will try renaming it for now, and if the problem continues, I woulld uninstall lazarus and dbbrowser making sure I download the 64 bit versions.

steveinalabama

  • New Member
  • *
  • Posts: 12
Re: Unable to connect to sqllite
« Reply #4 on: June 23, 2021, 01:37:22 am »
I renamed the dll under the Delphi install but the Lazarus program still fails. The db browser for SQLITE I have been using is a 64 bit version.

In Lazarus under help / About it says:" x86-64-win64-win32/win64"
Since it has W32 and win64 both there, does that mean it is one version that can run in either 32 bit or 64 bit environments?

egsuh

  • Hero Member
  • *****
  • Posts: 782
Re: Unable to connect to sqllite
« Reply #5 on: June 23, 2021, 04:31:29 am »
I think .dll bitness should match that of operating system --- Windows, I assume.

I put 64-bit sqlite3.dll under c:\windows\system32  if it is 64 bit. (32-bit one should be under c:\windows\SYSWOW64.  I'm not confusing), Because these folders are in the search paths by default (if not absolutely default, they are almost).

Sometimes I make copies of exe file to USB or CD. In those cases, I copy sqlite3.dll to the same folder as exe file. But on my development PC, I do not put sqlite3.dll in the Lazarus directory, project file directory, or exe file directory. The exe file may run on other directory than that the exe file resides.

This is my practice. You may try other approaches.   

And SQLite seems single-user system. If it is opened by dbbrowser, etc., you cannot open it in Lazarus (based on my experience which is limited). So please check these points first.

 

lucamar

  • Hero Member
  • *****
  • Posts: 4135
Re: Unable to connect to sqllite
« Reply #6 on: June 23, 2021, 06:21:11 am »
I think .dll bitness should match that of operating system --- Windows, I assume.

No, it should match that of the application.Windows itself can run either a 32 or 64 bit version of the DLL but a 32 bit process needs a 32 bit dll, and conversely for 64 bit ones.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

steveinalabama

  • New Member
  • *
  • Posts: 12
Re: Unable to connect to sqllite
« Reply #7 on: June 23, 2021, 06:58:32 am »
I uninstalled Lazarus and Sqlitestudio. I reinstalled both of them, and I copied the sqlite3.dll from
 sqlitestudio to c:\Lazarus and to the folder with the  database file.

I rebooted, started Lazarus, and put an sqlconnector and a sqlquery on a form.

If I set the connector to active in the IDE it accepts it, but as
soon as I compile and then run the program, it fails even before any code is executed. If I make connected = false in the IDE and I
have a buttonclick set the connector to connected it fails with the "...cannot load client library sqlite3.dll..." message.

I have a query I open after the connector is active, but it never gets there because the connector never gets connected.
It is as though it expects to find the sqlite3,dll in some other location than c:\lazarus or where the database file is, but where?

Anyone have a new approach?



egsuh

  • Hero Member
  • *****
  • Posts: 782
Re: Unable to connect to sqllite
« Reply #8 on: June 23, 2021, 07:19:54 am »
It do not have to be in the same location as DB file.
Copy it to a folder where your application's dpr file is, or exe file is created. I think dll file should be execution directory (or directories in the path).
I recommend to put it in the Windows\system32 folder, as if it succeed, you don't have to copy it to folders where you create the applications.

steveinalabama

  • New Member
  • *
  • Posts: 12
Re: Unable to connect to sqllite
« Reply #9 on: June 23, 2021, 07:27:21 pm »
Thank you.
I put the dll in Windows\system32 and I got a difference error: "transaction not set".
I added this line of code and it does connect now
sqlconnector1.transaction := sqlconnector1.transaction;
But when I tried to open the query I got the same error "transaction not set".
If tried adding this line sqlquery1.transaction := sqlconnector1.transaction - same error.
Then I tried sqlquery1.transaction := sqlquery1.transaction; and got the same error.

What is the suggested value for sqlquery1.transaction?


egsuh

  • Hero Member
  • *****
  • Posts: 782
Re: Unable to connect to sqllite
« Reply #10 on: June 24, 2021, 03:01:24 am »
Drop a TSQLTransaction component on the form or datamodule where your TSQLConnection is located, and wire them with properties --- set SQLConnection.Transaction to the TSQLTransaction component. Instead of TSQLConnection, TSQLite3Connection may be better, as it is customized for the specific database anyway.

For convenience, set TSQLTransaction properties as

    Action: caCommit
    Options.stoUseImplicit : true


Then your program shold work.
But you have to study the operation of transactions later in detail.



steveinalabama

  • New Member
  • *
  • Posts: 12
Re: Unable to connect to sqllite
« Reply #11 on: June 24, 2021, 04:20:17 am »
Thank you very much, but another unexpected problem has appeared.

I found a sample lazarus program guitarclub01 and it has a transaction component on it, and I figured I need to add that to my program. I did, so I recompiled to see if that fixes the transaction not set error. My unexpected problem is that when I compile my program the guitarclub program appears.I got completely out of Laxarus, and came in again and opened up my program.  But the same thing happens...the guitarclub program compiles.

I purposely changed code to force a syntax error, but the guitarclub compiles and my syntax error never happens.

When I go to the menu and select open recent, my pas file and form are deleted. I did not see any "project" file, something like a dproj file that Delphi uses. I cannot see how to open a different project.

Please enlighten me. Thanks

steveinalabama

  • New Member
  • *
  • Posts: 12
Re: Unable to connect to sqllite
« Reply #12 on: June 24, 2021, 04:28:40 am »
I went to file open and hard coded *.lpi in the file name box, and selected my own project, so now there is no more guitarclub that compiles, but my own. I will now implement your specific fixes. Thank you again

steveinalabama

  • New Member
  • *
  • Posts: 12
Re: Unable to connect to sqllite
« Reply #13 on: June 24, 2021, 05:23:10 am »
The program runs fine now. Thank you to all that helped me.

 

TinyPortal © 2005-2018