在Win IOT上连接到sqlite数据库

时间:2019-01-22 19:22:30

标签: sqlite raspberry-pi iot windows-10-iot-core

我遇到错误{SQLite.Net.SQLiteException:尝试连接到树莓派3上的sqllite数据库时,无法打开数据库文件:C:\ Data \ Users \ DefaultAccount \ Documents \ Storage.db(CannotOpen) ,使用WIN IOT是操作系统。我正在使用SQLite的SQLite.Net-PCL 3.1.1版实现。

var documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);    var fileName2 = "Storage.db";
var path2 = Path.Combine(documentsPath, fileName2);     

try
        {
            using (var connection = new SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path2))
            {

            }
        }
        catch (Exception ex)
        {
            string m_er = ex.ToString();
        }

1 个答案:

答案 0 :(得分:1)

我想您使用UWP应用程序。在Windows IoT核心版上,您可以使用FolderPermissions tool来使UWP应用可以访问此路径“ C:\ Data \ Users \ DefaultAccount \ Documents”。

FolderPermissions C:\Data\Users\DefaultAccount\Documents -e

由于您没有收到“拒绝访问”错误,因此我想您已经在Package.appxmanifest中添加了以下功能。

<uap:Capability Name="documentsLibrary" />

然后您的代码将起作用。 (我在具有Windows IoT核心版10.0.17763.107的Raspberry Pi 3上进行了测试)

enter image description here