How to access sqlite database outside the UWP application domain?

Xie Steven 831 Reputation points
2023-02-22T03:43:34.61+00:00

Hi,

I checked the document file-access-permissions . I have added the **broadFileSystemAccess** capability in the manifest file and enabled the 'file system' for my UWP app on Windows 10 settings.

Now, I want to open sqlite database on D:\xxx by using the Microsoft.Data.Sqlite 2.0 relevant APIs.

The code demo:

var path = @"D:\sqlitedbs\sample.db";
var sqliteConnection = new SqliteConnection(path);
sqliteConnection.Open();

Then, I got the exception:

Format of the initialization string does not confirm to specification starting at index 0.

My final target is to open the sqlite db and execute CRUD operations. How to get it?

Thanks,

Steven

Developer technologies Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2023-02-22T07:44:37.9+00:00

    Hello,

    Welcome to Microsoft Q&A!

    The broadFileSystemAccess capability only works for the Windows.Storage APIs. But the SqliteConnection is not using Storage API to open the db file. It is still using win32 or .net APIs to open files via path. This is not allowed in UWP apps. So you can't open the DB file just like this.

    You could try to get the DB file first by using Windows.Storage APIs and broadFileSystemAccess capability. Then you could copy the file into your app's local folder or installation folder. The SqliteConnection should work correctly when trying access the file in these two places.

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.