Slinky
Slinky

Reputation: 17

Delphi XE5 Android Dev "unable to open database file"

I followed this tutorial step by step Mobile Tutorial: Using SQLite (iOS and Android) but when I deploy my application on my android device and attempt to add an entry, I get the following error "unable to open database file"

Here is a snippet of my code:

procedure TForm1.rappadAfterConnect(Sender: TObject);
begin
      rappad.ExecuteDirect('CREATE TABLE IF NOT EXISTS notes(ID INTEGER PRIMARY KEY, title TEXT NOT NULL, content TEXT NOT NULL);');
end;

procedure TForm1.rappadBeforeDisconnect(Sender: TObject);
begin
  {$IF DEFINED(iOS) or DEFINED(ANDROID)}
  rappad.Params.Values['ColumnMetadataSupported'] := 'False';
  rappad.Params.Values['Database'] :=
      TPath.Combine(TPath.GetDocumentsPath, 'rappad.s3db');
  {$ENDIF}
end;

Does anyone know why is this actually happening? Thanks!

Upvotes: 0

Views: 3160

Answers (1)

Ken White
Ken White

Reputation: 125671

The code you have in your rappadBeforeDisconnect needs to be in BeforeConnect instead. There's no point in telling the connection where the database is located before you disconnect.

procedure TForm1.rappadBeforeConnect(Sender: TObject);
begin
  {$IF DEFINED(iOS) or DEFINED(ANDROID)}
  rappad.Params.Values['ColumnMetadataSupported'] := 'False';
  rappad.Params.Values['Database'] :=
      TPath.Combine(TPath.GetDocumentsPath, 'rappad.s3db');
  {$ENDIF}
end;

Upvotes: 2

Related Questions