加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 文档库中的UWP App SQLite Access数据库

发布时间:2020-12-15 08:35:43 所属栏目:百科 来源:网络整理
导读:问:我无法在Documents文件夹中打开SQLite数据库: 应用程序:通用Windows(10)平台 开发:C#,Visual Studio 2015 SQLite:使用SQLite.net 目标:Windows 10桌面和Windows 10手机 部署:从Visual Studio或Sideloaded(不需要存储部署) using SQLite;using SQLi
问:我无法在Documents文件夹中打开SQLite数据库:

应用程序:通用Windows(10)平台
开发:C#,Visual Studio 2015
SQLite:使用SQLite.net
目标:Windows 10桌面和Windows 10手机

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

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

我可以:

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

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

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

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
}

>将another.db3复制到Documents
>从那里复制到外部存储设备(SD卡)

我不能

>在Documents或SD中打开数据库

我使用FilePicker在Documents或SD中选择db
然后,在尝试打开数据库连接时,我使用File.Path属性

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

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

Exception thrown: ‘SQLite.Net.SQLiteException’ in SQLite.Net.dll
SQLite-GetAllVendors: Could not open database file: C:UsersmeDocumentsanother.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)应用程序的记忆棒上打开SQLite数据库.
Thx提前

解决方法

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读