如何使用Cordova在Windows Phone 8上使用现有的sqlite数据库 - c#

我正在使用Cordova 3.0构建一个混合应用程序。我使用插件将数据存储在sqlite数据库中。在android和ios上,我有一些脚本,这些脚本将数据库复制到应用程序的“ documents”文件夹中,在这里我可以读取/写入该预填充数据库。现在我想在Windows Phone 8上将其存档。

我找到了以下教程:
http://wp.qmatteoq.com/import-an-already-existing-sqlite-database-in-a-windows-8-application/

但这与科尔多瓦无关。

这是我的代码如下所示:

namespace com.example.hello
{
   public partial class MainPage : PhoneApplicationPage
   {
    // Constructor
    public MainPage()
    {
        InitializeComponent();

        this.CordovaView.Loaded += CordovaView_Loaded;
    }

    private async void CordovaView_Loaded(object sender, RoutedEventArgs e)
    {
        await CopyDatabase();
        this.CordovaView.Loaded -= CordovaView_Loaded;
    }

    private async Task CopyDatabase()
    {
        bool isDatabaseExisting = false;

        try
        {
            StorageFile storageFile = await ApplicationData.Current.LocalFolder.GetFileAsync("my.db");
            isDatabaseExisting = true;
        }
        catch
        {
            isDatabaseExisting = false;
        }

        if (!isDatabaseExisting)
        {
            StorageFile databaseFile = await Package.Current.InstalledLocation.GetFileAsync("my.db");
            await databaseFile.CopyAsync(ApplicationData.Current.LocalFolder);
        }
    }
}
}

但是我总是得到一个异常“ System.IO.FileNotFoundException”。但是.db文件仍然在正确的位置。如果我使用代码段显示“ ApplicationData.Current.LocalFolder”中的所有文件,则我的sqlite填充仍然存在。

我还有一个要旨,上面有屏幕截图https://gist.github.com/pille72/9615840

参考方案

将生成操作从Resource更改为Content

Windows Phone WNS通知导航到特定页面 - c#

它是Windows运行时,Windows Phone专用项目。我正在使用Azure和Azure通知中心。所以我的问题是,有谁愿意如何导航到某些特定页面并发送ID等参数。这是我的吐司模板,如字符串中所述: var toast = @"<toast><visual><binding template=""…

Windows Phone 7-C#如何在代码中使用ListPickerItem而不会崩溃? - c#

到目前为止,Listpickeritem似乎有点头痛,因为它很容易崩溃。我有以下代码,在运行应用程序时选择listpickeritem时,该代码会崩溃:for (int i = 1; i <= 100; i++) { ListPickerItem item = new ListPickerItem(); item.Content = i.ToStrin…

SQLite-无法连接数据库 - c#

背景:1.它是一个使用Sqlite databse的C#应用​​程序2.如果不存在db,则此应用程序将创建一个空的db,并将数据从服务器同步到该数据库。问题:1.有时应用程序突然崩溃。似乎有一些未处理的异常。2.即使我重新启动该应用程序,它也立即崩溃。临时解决方案:1.将数据库复制到其他位置,然后删除原始数据库。2.运行该应用程序。没有崩溃。由于不存在任何数…

SQLite PDO绑定不起作用? - php

我觉得我对此一无所知。我有三个简单的表。一个用户表,一个角色表和一个role_user表,该表以多对多关系连接用户和角色。对于用户角色,我有以下代码:$query = $pdo->prepare('select roles.* from roles inner join role_user on roles.id = role_user.ro…

SQLite.Net,相当于SQLite位数据类型的C# - c#

我在C#中声明以下课程[Table("Employee")] public class Employee { [PrimaryKey,AutoIncrement] public int EmployeeId { get; set; } public DateTime DateOfJoining { get; set; } public s…