2016-09-13 57 views
0

所以我已經做了一個應用程序是一個測試應用程序,它工作得很好使用sqlite-net-pcl和我現在正在製作一個實際的應用程序,我得到這個奇怪的錯誤,我不能圖爲什麼。我發現確切的same question已經在這裏問過,但它沒有提供任何真正的答案,它是在一年前。Xamarin形式爲SQL的SQLite

System.Exception:構建配置中出現問題。這是誘餌程序集,用於通過可移植庫進行引用,並且絕不應該成爲應用程序的一部分。改用適當的平臺組件。

public SQLite.SQLiteConnection GetConnection() 
    { 
     var sqliteFilename = "TestDB.db3"; 
     string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); // Documents folder 
     var path = Path.Combine(documentsPath, sqliteFilename); 
     // Create the connection 
     var conn = new SQLite.SQLiteConnection(path);//HERE IS WHERE IT THROWS THE EXCEPTION 
     // Return the database connection 
     return conn; 
    } 

應用程序適用於所有其他平臺我都試過,除了Android和我的測試應用程序,只是正常使用完全相同的引用和同一類以及我只是不能想出辦法來的。我曾嘗試引用sqlite-net-pcl並創建了一個新類,但仍然無法正常工作。任何幫助將不勝感激 非常感謝你

+0

你有SQLite的包安裝在您的共享項目和個人平臺項目中? – Jason

+0

是的我重複檢查,我已經卸載並重新安裝了多次 – hartk1213

+0

您是否嘗試過清理並重建您的項目和解決方案?也許一些老的/錯誤的DLL被緩存在那裏 –

回答

1

這裏是我使用 https://github.com/oysteinkrog/SQLite.Net-PCL

檢查你在你的Android項目中引用SQLite.Net.Platform.XamarinAndroid之一。

這裏是一個工作正常,我的代碼(我還包括SQLite.Net.Async-PCL)

public SQLiteAsyncConnection GetConnection() 
     { 
      // database name 
      const string SQLITE_FILENAME = "MyDB.db3"; 

      // Get app folder 
      string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); 
      string path = Path.Combine(documentsPath, SQLITE_FILENAME); 

      var plat = new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid(); 
      var sqliteConnection = new SQLiteConnectionWithLock(plat, new SQLiteConnectionString(path, true)){BusyTimeout = TimeSpan.FromSeconds(5)}; 
      var conn = new SQLiteAsyncConnection(() => sqliteConnection, 
       TaskScheduler.FromCurrentSynchronizationContext()); 

      // Return the database connection 
      return conn; 
     } 

想這應該工作:

public SQLiteConnection GetConnection() 
     { 
      // database name 
      const string SQLITE_FILENAME = "MySIT.db3"; 

      // Get app folder 
      string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); 
      var plat = new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid(); //important! 
      string path = Path.Combine(documentsPath, SQLITE_FILENAME);    
      var conn = new SQLiteConnection(plat, path); 

      // Return the database connection 
      return conn; 
     }