【问题标题】:Windows Phone 8.1 WRT & SQLite, error on creating databaseWindows Phone 8.1 WRT & SQLite,创建数据库时出错
【发布时间】:2015-05-24 20:05:00
【问题描述】:

我正在寻找在我的 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);

但如果我运行它,我会看到,在带有注释“错误!!!”的行中第一个,以下消息:

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 statiaggiunti 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。

但是,如果我尝试在包管理器控制台中添加以下命令“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

【问题讨论】:

  • 如果文件不存在,预计GetFileAsync 会失败。如果继续执行会发生什么?
  • 感谢您的回答!如果我继续,我会在 SQLiteAsync.cs 中看到另一个错误(在公共任务 CreateTableAsync 中):抛出异常:mscorlib.ni.dll 中的“System.ArgumentException” Ulteriori informazioni:对事件 TaskScheduled 使用未定义的关键字值 1。我该如何解决?谢谢!
  • 你试过调试你的代码吗?您尚未显示调用 CreateTableAsync 的代码
  • 我认为,这取决于缺少 Visual C++ 组件。我尝试从教程中下载另一个简单的项目,该项目肯定是正确的,我看到了同样的警告。现在,问题是,如何在我的项目中正确安装或链接或引用 Visual C++ 2013 库组件?谢谢大家。 PS 我已经从microsoft.com/it-it/download/details.aspx?id=40784 下载了它,我已经通过双击正确安装了,但是我现在看到了同样的警告。
  • 如果在Visual Studio中新建一个C++ Direct3D应用,能否成功部署到手机上?

标签: sqlite windows-phone-8.1


【解决方案1】:

我和你有同样的错误,

我在我的 Windows phone 项目中引用了“Microsoft Visual C++ 2013 Runtime Package for Windows phone”,在我的 Windows 8.1 项目中引用了“Microsoft Visual C++ 2013 Runtieme package for Windows”!!!

【讨论】:

    猜你喜欢
    • 2014-11-05
    • 1970-01-01
    • 2017-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-10
    相关资源
    最近更新 更多