我正在寻找在我的Win Phone WRT 8.1应用程序中创建一个SQLite数据库;我已经阅读了这篇文章Create a SQLite Database in Windows Phone 8.1 Class Library,我试着写这个课:
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,Version = 3.8.10.2”dipende dai seguenti SDK“Microsoft.VCLibs,version = 12.0”che non sono stati aggiunti al progetto o non sono stati trovati。 Assicurarsi di aggiungere queste dipendenze al progettooèpossibileche si verifichino problemi di runtime。 Èpossibileaggiungere dipendenze al progetto mediante Gestione riferimenti。
但是,如果我尝试在程序包管理器控制台中添加以下命令“Install-Package Microsoft.VCLibs.120.SDKReference -PRE”,我会看到此错误:
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