文档库中的UWP App SQLite Access数据库 [英] UWP App SQLite Access database in Documents Library

查看:411
本文介绍了文档库中的UWP App SQLite Access数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问:我无法在我的Documents文件夹中打开SQLite数据库:



Windows(10)平台

开发:C#,Visual Studio 2015

SQLite:使用SQLite.net

目标:Windows 10桌面和Windows 10手机

部署:从Visual Studio或Sideloaded(不需要Store部署)

 使用SQLite; 
使用SQLite;
使用SQLite.Net;
使用SQLite.Net.Async;
使用SQLite.Net.Attributes



我可以:



打开并从包含在项目中的数据库读取内容:

 使用(SQLite.Net。 SQLiteConnection conn = new SQLite.Net.SQLiteConnection 
(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(),.\\mydb.db3))
{
//读取查询
}

打开/创建并读取/写入数据库到apps工作区:

  string path = Path.Combine 
(Windows.Storage.ApplicationData.Current.LocalFolder.Path, db3);

使用(SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection
(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(),path))
{
// CRUD
}




  • 复制另一个。 db3到文档

  • 从那里复制到外部存储设备(SD卡)



I不能




  • 在Documents或SD中打开数据库



我使用FilePicker选择文档中的数据库或SD

然后在尝试打开数据库连接时使用File.Path属性

  Windows.Storage.StorageFile File = await FilePicker.PickSingleFileAsync(); 
string path = File.Path;

我尝试打开该连接时收到以下错误消息:


抛出的异常:SQLite.Net.dll中的'SQLite.Net.SQLiteException'

SQLite-GetAllVendors:无法打开数据库文件:C: \Users\me\Documents\another.db3(CannotOpen)


已添加SQLite .db和.db3文件关联。

 < Extensions> 
< uap:Extension Category =windows.fileTypeAssociation>
< uap:FileTypeAssociation Name =。db>
< uap:DisplayName> SqliteDB< / uap:DisplayName>
< uap:EditFlags OpenIsSafe =true/>
< uap:SupportedFileTypes>
< uap:FileType> .db< / uap:FileType>
< uap:FileType> .db3< / uap:FileType>
< / uap:SupportedFileTypes>
< / uap:FileTypeAssociation>
< / uap:Extension>
< / Extensions>
< / Application>
< / Applications>

已添加相关功能

 < Capabilities> 
< Capability Name =internetClient/>
< uap:Capability Name =picturesLibrary/>
< uap:Capability Name =documentsLibrary/>
< uap:Capability Name =videosLibrary/>
< uap:Capability Name =userAccountInformation/>
< uap:Capability Name =removableStorage/>
< DeviceCapability Name =webcam/>
< DeviceCapability Name =location/>
< / Capabilities>

当然有一些方法可以在Documents或者记忆棒形成通用Windows(10)应用程序。

提前Thx

解决方案

因为SQLite直接打开数据库文件,而不是通过文件代理,它只能看到应用程序安装和应用程序数据(应用程序有直接文件权限读取和读/写的目录)中的数据库。 / p>

更改此操作将需要更新SQLite以使用来自文件代理对象(StorageFile和StorageFolder)的流访问具有通过功能,选择器等授予的权限的位置。 / p>

Q: I can't open a SQLite database in my Documents folder:

App: Universal Windows (10) Platform
Development: C#, Visual Studio 2015
SQLite: Using SQLite.net
Targets: Windows 10 Desktop and Windows 10 Phone

Deployment: From Visual Studio or Sideloaded (Do not need Store deployment)

using SQLite;
using SQLite;   
using SQLite.Net;   
using SQLite.Net.Async;   
using SQLite.Net.Attributes

I can:

Open and read from a database included in the project as content:

using (SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection
(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), ".\\mydb.db3"))
{
//Read queries
}

Open/Create and Read/Write a database to the apps workspace:

string path = Path.Combine
(Windows.Storage.ApplicationData.Current.LocalFolder.Path,"another.db3");

using (SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection
(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path))
{
//CRUD
}

  • Copy another.db3 to Documents
  • From there copy to an External Memory Device (SD Card)

I can't

  • Open the database in Documents or SD

I use a FilePicker to choose the db in Documents or the SD
I then use the File.Path property when attempting to open the database connection

Windows.Storage.StorageFile File = await FilePicker.PickSingleFileAsync();  
string path = File.Path;

I get the following error message when I attempt to open that connection:

Exception thrown: 'SQLite.Net.SQLiteException' in SQLite.Net.dll
SQLite-GetAllVendors: Could not open database file: C:\Users\me\Documents\another.db3 (CannotOpen)

Have added SQLite .db and .db3 file associations.

      <Extensions>
        <uap:Extension Category="windows.fileTypeAssociation">
          <uap:FileTypeAssociation Name=".db">
            <uap:DisplayName>SqliteDB</uap:DisplayName>
            <uap:EditFlags OpenIsSafe="true" />
            <uap:SupportedFileTypes>
              <uap:FileType>.db</uap:FileType>
              <uap:FileType>.db3</uap:FileType>
            </uap:SupportedFileTypes>
          </uap:FileTypeAssociation>
        </uap:Extension>
      </Extensions>
    </Application>
  </Applications>

Have added the relevant Capabilities

  <Capabilities>
    <Capability Name="internetClient" />
    <uap:Capability Name="picturesLibrary" />
    <uap:Capability Name="documentsLibrary" />
    <uap:Capability Name="videosLibrary" />
    <uap:Capability Name="userAccountInformation" />
    <uap:Capability Name="removableStorage" />
    <DeviceCapability Name="webcam" />
    <DeviceCapability Name="location" />
  </Capabilities>

Surely there is some way to open a SQLite database in Documents or on a memory stick form a Universal Windows (10) app.
Thx in advance

解决方案

Because SQLite opens the database file directly rather than going through the file broker it can only see databases in the app install and application data (the directories that the app has direct file permissions to read and read/write respectively).

Changing this would require an update to SQLite to use streams from the file broker objects (StorageFile and StorageFolder) to access locations that have permissions granted via capabilities, pickers, etc.

这篇关于文档库中的UWP App SQLite Access数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆