Untraceable access violation when opening a sqlite db the 2nd time lazarus / 16-Databases ---------------------------------------------------------------------- dietmar · 2021-09-29 18:15 Hi, I am using this code to open a sqlite DB: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function TDBHelper.OpenDB(fn: String): Boolean;var s: String;begin    SQLite3Connection.DatabaseName := fn;    try      SQLite3Connection.Open;      if SQLite3Connection.Connected then      begin        SQLTransaction.Active := True;      end...  Then I am executing SELECT statements on it which works fine. Then, after closing the DB via SQLite3Connection.Close; I am running into access violations when I try to (re)open the database. What am I doing wrong? Thx, --Dietmar ---------------------------------------------------------------------- MarkMLl · 2021-09-29 19:43 Quote from: dietmar on September 29, 2021, 08:15:59 pmWhat am I doing wrong? Not attaching a complete program that people can use to duplicate your problem. MarkMLl ---------------------------------------------------------------------- marcov · 2021-09-29 20:05 I never used sqllite with transaction, but maybe close transaction first ? Maybe the transaction component is left in some indefinite state. ---------------------------------------------------------------------- dietmar · 2021-09-30 13:07 Attached is my small test project, but unfortunately, that even throws an error before the "interesting part": Access violation reading... in line 46 of tdbhelper. Don't know, what's going wrong here, it works in my main program. If it runs, you should be able to reproduce the error by "open" -> "close" -> "open" buttons... --Dietmar ---------------------------------------------------------------------- balazsszekely · 2021-09-30 15:14 Hi dietmar, QuoteAttached is my small test project, but unfortunately, that even throws an error before the "interesting part": Access violation reading... in line 46 of tdbhelper. Don't know, what's going wrong here, it works in my main program. Form DBHelper is nil. You have to choices:     1. Add DBHelper to the auto-create forms(project options)     2. Create the form before calling method OpenDB: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i    dbHelper := TdbHelper.Create(Application);  //this line  if (DBHelper.OpenDB(ExtractFilePath(Application.Location) + 'test.db')) then begin    Query := TSQLQuery.Create(nil);    try      Query := DBHelper.SelectQuery('SELECT * FROM Owner LIMIT 1;');      StaticText1.Caption := Query.FieldByName('Wiz_Name').AsString;    finally      Query.Free;    end;  end; ---------------------------------------------------------------------- dietmar · 2021-09-30 16:25 Ok, after adding the form the the loadings, one can start testing with the real problem/error... thx, GetMem. --Dietmar ---------------------------------------------------------------------- balazsszekely · 2021-09-30 18:00 @dietmar QuoteOk, after adding the form the the loadings, one can start testing with the real problem/error... thx, GetMem. See attached project. Instead of TdbHelper(TForm), please use a TDataModule. ---------------------------------------------------------------------- dietmar · 2021-09-30 18:29 Thanks a lot for your efforts! And I will start to read into TDataModule now... --Dietmar