2014-10-03 39 views
4

我想在我的Windows 8.1現代UI應用程序中實現數據庫。 我成功地爲Windows Phone 8.1應用程序做了這個,但它不適用於新的Windows 8.1應用程序。無法打開數據庫文件Windows應用商店應用8.1

我有一個SQLiteException有消息Could not open database file: MyAppBase.db (CannotOpen)當我實例化SQLiteConnection

public static DatabaseHelper Instance 
    { 
     get 
     { 
      if (_instance == null) 
      { 
       _instance = new DatabaseHelper(); 
      } 

      return _instance; 
     } 
    } 

    public DatabaseHelper() 
    { 
     _connection = new SQLiteConnection(DATABASE_NAME); 

     _connection.CreateTable<UserEntity>(); 
    } 

我遵循這個步驟: 加入 '源碼網' 來的NuGet參考,經過 'SQLite,讓Windows運行時(Windows 8.1中)' 和項目引用上的'Microsoft Visual C++ 2013 Runtime Package for Windows',Targetted build to x86。

我如何得到這個工作?

回答

8

的SQLite需要一個路徑來創建數據庫不僅僅是一個數據庫名

嘗試這樣的事情

string path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, DATABASE_NAME); 

_connection = new SQLite.SQLiteConnection(path) 

希望這有助於

+0

由於它的作品! – alvinmeimoun 2014-10-06 07:51:57

0

使用

string path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, databasePath); 
相關問題