Windows Phone 8.1 WRT和SQLite,创建数据库时出错

问题描述 投票:0回答:1

我正在搜索在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,版本= 3.8.10.2”扩展SDK“ Microsoft.VCLibs,版本= 12.0”,请按照以下说明进行操作。正常运行时遇到问题的提示。 Èpossibile aggiungere dipendenze al progetto midte 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
sqlite windows-phone-8.1
1个回答
0
投票

我和你有同样的错误,

我在Windows Phone项目中引用了“用于Windows Phone的Microsoft Visual C ++ 2013 Runtime程序包”,在Windows 8.1项目中引用了“用于Windows的Microsoft Visual C ++ 2013 Runtieme程序,并且可以正常工作!!

© www.soinside.com 2019 - 2024. All rights reserved.