Windows 10 removableStorage SQLite database

539 views Asked by At

I am trying to create an external sqlite database, I follow and tested text files in the removable storage and works. So then I try to create a database in the removable Storage:

public static async Task<String> CreateDatabase(string name)
    {
        var folder = await FindRemovableStorage();
        if (folder != null)
        {
            var file = await folder.CreateFileAsync(name, CreationCollisionOption.ReplaceExisting);
            if(file!=null)
            {
                var ret = $"{folder.Name}{file.Name}";
                return ret;
            }
        }
        return null;

    }

public async void ThirdCase()
    {
        var path =await DataLoggerService.CreateDatabase("db.dat");

        var connection = new SQLite.Net.SQLiteConnection(new SQLitePlatformWinRT(), path); //Cannot Open

    }

I am testing on the desktop, and returns CannotOpen. Does anyone has created a database out from the typical local folder?

More details of what I did here: datalogger

When I finish I want to implement in a Raspberry Pi, theorically is the same code for the Windows IoT or is there any change in the SQLitePlatformWinRT?

EDITION: More analisys:

I have tested a database with the typical, working like a charm:

Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db.dat");

I wanted to create the database in an external storage, to do that I need to add the following steps:

1.- Add Capability to use removablestorage. 2.- Add file type association in order to have rights to manage that kind of files

(The details here: http://expediteapps.com/blog/data-logger-with-windows-10-iot-in-progress/)

So then I change the path to the removable storage path like “E:\db.dat” and it always tells CannotOpen.

The SQLite library PCL It arrives to here:

SQLiteApiWinRT.cs

public Result Open(byte[] filename, out IDbHandle db, int flags, IntPtr zvfs)
{
    Sqlite3DatabaseHandle internalDbHandle;
    var ret = (Result)SQLite3.Open(filename, out internalDbHandle, flags, zvfs);
    db = new DbHandle(internalDbHandle);
    return ret;
}

Where Open is

[DllImport("sqlite3", EntryPoint = "sqlite3_open_v2", CallingConvention = CallingConvention.Cdecl)]

public static extern Result Open(byte[] filename, out IntPtr db, int flags, IntPtr zvfs);

where I am using:

SQLite.UAP.2015, Version=3.8.10

MORE Aditions:

I have tested this library https://www.nuget.org/packages/SQLitePortable/ and I finish in the same error, so it is internal.

And here is where the road ends, any help?

1

There are 1 answers

2
Kyagos On

Since you asked for RaspberryPi 3 Windows 10 IoT SQLite implementation, here are the steps I followed to make it work: (Visual Studio 2015 Community)

  1. Download: .vsix package for Universal Windows Platform from the sqlite page
  2. Install the package from the download folder
  3. In Visual Studio go to Tools->NuGet Package Manager->Package Manager Console and type in: Install-Package SQLite.Net-PCL
  4. Add required References (Right Mouse Button -> Add Reference -> Universal Windows -> Extensions)

Here I choose the following:

  • Microsoft Visual C++ 2013 Runtime Package for Windows Universal
  • SQLite for Universal Windows Platform
  • Visual C++ 2015 Runtime for Universal Windows Platform Apps
  • Windows IoT Extensions for the UWP (Since I am using RPi 3 with GPIO Pins)

Basically I followed chrisbriggsy steps and had to add some more resources cause SQLite didn't work