2016-10-20 21 views
0

我想要打開或創建(如果不存在)數據庫文件,但是當我嘗試創建SQLiteConnection類的新實例時,它拋出一個帶有錯誤代碼30的Exception(誤用)amd無法打開數據庫文件。Xamarin.Android SQLiteConnection無法打開數據庫文件

這裏是我的代碼:

class DatabaseOpen 
{ 
    protected SQLiteConnection db; 
    ... // Here are another attributes of the class, which is not relevant to the database connection. 
    public DatabaseOpen(String filename="noNameFree") // String filename = "noNameFree" 
    { 
     String dbPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); 
     dbPath = Path.Combine(dbPath, filename+".db3"); 
     Java.IO.File dbFile = Application.Context.GetDatabasePath(dbPath); 
     dbFile.Mkdirs(); 
     var dbObject = new SQLiteConnection(dbPath); 
     db = dbObject; 
    } 
    ... // Here are the other methods of the class which is not relevant to the database connection. 
} 

在變量上面的代碼中設置好的以下路徑:

/data/data/<AppName>.<AppName>/files/noNameFree.db3 

我看不出有什麼我所著錯了。我希望有人看到代碼的問題。

回答

0

我將應用程序從SD卡移動到內部存儲器,然後它開始工作。之後,我把它移回到我的SD卡上,它仍然在工作。我認爲在部署Visual Studio沒有安裝它到正確的地方。

注意: 我認爲在這種情況下SQLite.Net不會拋出一個MISUSE異常。我會爲開發者創建一個關於這個問題。

相關問題