2

I use Zeoslib components to interact with my SQLite database file. I have several SQLite database files in a folder. So, I want to be able to open any one of them using Zeoslib component. However, it won't let me. It opens the first database successfully but any database file I open after that, I get access violation error. For the life of me, I simply can't figure it out WHY.

Here is how I open database file.

procedure TMainFrm.Open1Click(Sender: TObject);
var currdb:string;
begin
 OpenDlg.InitialDir := BaseDir;
 if OpenDlg.Execute = true then
 begin
      currdb := Extractfilename(OpenDlg.FileName);
      DataModule1.ZConnection1.Disconnect;
      DataModule1.ZConnection1.Protocol := 'SQLite-3';
      DataModule1.ZConnection1.Database :=baseDir + currdb;

      DataModule1.Query1.SQL.Clear;
      DataModule1.Query1.SQL.Add('SELECT * FROM MyTable'); // <<<<--- ZConnection1 is Query1 database connection.

      DataModule1.ZConnection1.Connect; // <<<<<-------Here is where I get ACCESS VIOLATION all the time.
      UpdateGrid; // <<<<<<<----- Here is where the Query is executed and the DBGrid is updated.
 end;
end;

I don't know why this is. Is this mean I can't switch database from another using Zeoslib component?

Sir Rufo
  • 18,395
  • 2
  • 39
  • 73
ThN
  • 3,235
  • 3
  • 57
  • 115
  • 2
    You can try it with `ZConnection1.Protocol:='sqlite-3';` instead of `'SQLite-3'` . – moskito-x Nov 12 '14 at 15:57
  • @moskito-x Oh you are KIDDING me. I spent a whole day beating my head against the wall all because of few letters were uppercase. OMG!!! I thought it wouldn't matter, but apparently it does. – ThN Nov 12 '14 at 16:34
  • 2
    Good to know `ZConnection1.Protocol` is case sensitive. And as a note, it is a good behavior to close the dataset, before disconnect. Do not trust always the automatic by "database disconnect". `if Query1.Active then ...` – moskito-x Nov 12 '14 at 17:05

1 Answers1

2

The problem is in the TZConnection.Protocol value capitalization. Change the Protocol value from SQLite-3 to sqlite-3.

TLama
  • 75,147
  • 17
  • 214
  • 392
ThN
  • 3,235
  • 3
  • 57
  • 115