W. IoT上的UWP永久存储数据

时间:2017-02-04 17:46:41

标签: .net uwp windowsiot

设置:

  

使用Windows 10 IoT的Raspberry Pi3。

     

Visual Studio(使用VB)。

     

该应用程序是一个简单的后台应用程序。

我使用“Windows.Storage.ApplicationData.Current.LocalFolder.Path”文件夹来保存SQLite .net文件。但是当我从Debug切换到Release时,应用程序文件夹被删除。这很正常,好的。

但是有一个替代文件夹,没有空间和权限限制来保存数据库文件?

这是一个内部项目,安全性没有太大问题,也不会发布,所以我不介意与其他应用共享,也不是明智的数据。

DB CLASS

Public Class SQLLite

    <Table("TABLE_TEMP")>
    Private Class TABLE_TEMP

        <PrimaryKey, AutoIncrement>
        Public Property ID As Integer
        Public Property temp As Double
        Public Property humidity As Integer
        Public Property relay As Integer
        Public Property data As DateTime

    End Class

    Private conn As SQLite.Net.SQLiteConnection

    Sub New(_path As String)

        '### THIS WORK      
        'Dim Path As String = Path.Concat(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "\db.sqlite")

        '### THIS NOT WORK
        Dim Path As String = Path.Concat(_path, "\db.sqlite") 

        conn = New SQLite.Net.SQLiteConnection(New SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), Path, False)
        Try

            Dim result As String = conn.ExecuteScalar(Of String)("SELECT name FROM sqlite_master WHERE type='table' AND name='TABLE_TEMP'")
            If result <> "TABLE_TEMP" Then
                conn.CreateTable(Of TABLE_TEMP)()
            End If

        Catch exsql As SQLite.Net.SQLiteException
            Debug.WriteLine("EX_SQL: " & exsql.Message)
        Catch ex As Exception
            Debug.WriteLine("EX: " & ex.Message)
        End Try

    End Sub

    .
    .
    .
    ' OTHER DB FUNCTIONS
    .
    .
    .
End Class

致电DB CLASS

Dim f As Windows.Storage.StorageFolder = Windows.Storage.KnownFolders.MusicLibrary
Dim musicLibrary = Await Windows.Storage.StorageLibrary.GetLibraryAsync(Windows.Storage.KnownLibraryId.Music)

Dim dbSqlLite As New WIoTLibrary.SQLLite(musicLibrary.SaveFolder.Path)

对于工作,你需要NuGet包 SQLite.Net-PCL

0 个答案:

没有答案