2015-05-24 45 views
0

我正在寻找在我的Win Phone WRT 8.1应用程序中创建SQLite数据库;我读过这篇文章Create a SQLite Database in Windows Phone 8.1 Class Library,我已经试着写这个类:Windows Phone 8.1 WRT和SQLite,创建数据库时出错

using SQLite; 
using System; 
using System.Threading.Tasks; 
using Windows.Storage; 

namespace Functional_Timer 
{ 
    class DatabaseHelper 
    { 

     private String DB_NAME = "DATABASENAME.db"; 

     public SQLiteAsyncConnection Conn { get; set; } 

     public DatabaseHelper() 
     { 
      Conn = new SQLiteAsyncConnection(DB_NAME); 
      this.InitDb(); 

     } 

     public async void InitDb() 
     { 
      // Create Db if not exist 
      bool dbExist = await CheckDbAsync(); 
      if (!dbExist) 
      { 
       await CreateDatabaseAsync(); 
      } 
     } 

     public async Task<bool> CheckDbAsync() 
     { 
      bool dbExist = true; 

      try 
      { 
       //ERRORE!!! 
       StorageFile sf = await ApplicationData.Current.LocalFolder.GetFileAsync(DB_NAME); 
      } 
      catch (Exception) 
      { 
       dbExist = false; 
      } 

      return dbExist; 
     } 

     private async Task CreateDatabaseAsync() 
     { 
      //add tables here 
      //example: await Conn.CreateTableAsync<DbComment>(); 
     } 

    } 
} 

而且我已经叫这个类在我的应用程序的主界面如下指令:

this.InitializeComponent(); 
     commentDataSource = new CommentDataSource(db); 

但是如果我运行它,我会看到与评论“ERRORE !!!”相关的行的第一条消息:

Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.ni.dll 
Ulteriori informazioni: The system cannot find the file specified. (Exception from HRESULT: 0x80070002) 

为什么?你能帮助理解并解决它吗?非常感谢大家。

编辑:在控制台中,我看到消息

L'SDK “SQLite.WP81,版本= 3.8.10.2” dipende戴seguenti SDK “Microsoft.VCLibs,版本= 12.0” 切非索诺为static aggiunti al progetto o non sono stati trovati。 Assicurarsi di aggiungere queste dipendenze al progetto oèpossibile che si verifichino problemi di runtime。 Èpossibile aggiungere dipendenze al progetto mediante Gestione riferimenti。

但是,如果我尝试添加这一个写下面的命令包管理器控制台“安装,包Microsoft.VCLibs.120.SDKReference - 售前”,我看到这个错误:

Install-Package : Unable to find package 'Microsoft.VCLibs.120.SDKReference' 

At line:1 char:1 

+ Install-Package Microsoft.VCLibs.120.SDKReference -Pre 

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

    + CategoryInfo   : NotSpecified: (:) [Install-Package], Exception 

    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand 
+0

如果文件不存在,预计'GetFileAsync'会失败。如果你继续执行会发生什么? –

+0

感谢您的回答!如果我继续,我会在SQLiteAsync.cs(在公共任务CreateTableAsync中)看到另一个错误:引发异常:mscorlib.ni.dll中的'System.ArgumentException' 更多信息:使用未定义的关键字值1作为事件TaskScheduled。 我该如何解决它?谢谢! – Archimede

+0

您是否尝试过调试您的代码?你没有显示代码,你调用CreateTableAsync –

回答

0

我像你一样的错误,

我在Windows Phone Project和Windows的“Microsoft Visual C++ 2013 Runtieme包”中引用了“Windows Phone的Microsoft Visual C++ 2013运行时包”,我的Windows 8.1项目和工作!

相关问题