2014-09-20 5 views
3

여기에 지침을 따라 http://developer.xamarin.com/guides/cross-platform/xamarin-forms/working-with/databases/ - SQLite 데이터베이스에 동 기적으로 연결합니다.Xamarin.Forms SQLite.Net.Async를 사용하여

public SQLiteConnection GetConnection() 
{ 
    var dbFilname = "localDB.db3"; 
    string docsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); 
    var path = Path.Combine(docsPath, dbFilname); 

    var plat = new SQLitePlatformAndroid(); 
    var conn = new SQLiteConnection(plat, path); 
    return conn; 
} 

비동기 연결 (SQLiteAsyncConnection)으로 변경하려고하지만 작동시키지 못합니다. ,

연결 기능 : -

여기의 지시에 따라 https://components.xamarin.com/gettingstarted/sqlite-net 그냥 작동하지 않는 매개 변수

var conn = new SQLiteAsyncConnection(path); 

로 경로를 필요로 - 그것은 오류가 예상되는 매개 변수는 말한다 a TaskScheduler 및 TaskCreationOptions

나는 무엇을 해야할지 잘 모르고 일하는 예제를 찾을 수 없었습니다. 당신은 단순히 getConnection 메소드를 재사용 할 수

답변

3

사전에

덕분에 당신은 이미이 같은 비동기 연결을 만들 :

var asyncDb = new SQLiteAsyncConnection(() => GetConnection()); 
+1

고마워요. 그리고 같은 문제가있는 사람은 여기에 해결책이 있습니다 (http://www.captechconsulting.com/b). log/nicholas-cipollina/cross-platform-sqlite-support- % E2 % 80 % 93-part-1)도 작동합니다. – user1667474

+2

죽은 링크는 삭제하거나 변경하십시오. – peterincumbria

0

자 마린 플랫폼 안드로이드 구성, iOS 및 WP basicaly 동일

public SQLiteAsyncConnection GetConnectionAsync() 
     { 
      const string fileName = "MyDB.db3"; 
      var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); 
      var path = Path.Combine(documentsPath, fileName); 

      var platform = new SQLitePlatformAndroid(); 

      var param = new SQLiteConnectionString(path, false); 
      var connection = new SQLiteAsyncConnection(() => new SQLiteConnectionWithLock(platform, param)); 

      return connection; 
     }