2014-02-08 24 views
0

我跟着本教程一步一步Mobile Tutorial: Using SQLite (iOS and Android)但當我在我的android設備上部署我的應用程序並嘗試添加一個條目時,出現以下錯誤「無法打開數據庫文件」Delphi XE5 Android Dev「無法打開數據庫文件」

這裏是我的代碼片段:

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; 

有誰知道這是爲什麼實際發生的?謝謝!

回答

2

您在rappadBeforeDisconnect中的代碼需要位於BeforeConnect。在將斷開連接之前,告知連接數據庫所在的位置毫無意義。

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; 
+0

謝謝!其實我只是注意到了那麼真的!這是因爲在對象檢查員中,我意外地點擊了BeforeDisconnect過程而不是BeforeConnect。 DUR!愚蠢的我......在這次事故中一直困惑和迷惑了很多年。謝謝! :) – Slinky

相關問題