0

I'm trying to create the database file to initialize it but I'm getting "Access Denied" error during execution. I think is something related with permissions but I'm not able to find any information that could fix it, since every guide I check does it the same way. This is an UWP application using C# and SQLite library. Thanks in advance for the help.

In the past I've tried to also create json file with other methods but I've never been able to create a file from a UWP application

Code that raises an error:

private const string DBName = "data.sqlite";

if (!File.Exists(Path.GetFullPath(DBName)))
{
    SQLiteConnection.CreateFile(DBName);
    RecentlyCreated = true;
}

Error message:

System.UnauthorizedAccessException: 'Access to the path 'C:\Users\myuser\source\repos\Pass\Pass\bin\x64\Debug\AppX\dataAccount.sqlite' is denied.'

1 Answer 1

3

UWP has a very limited access to the user filesystem, as it described at File access permissions specification. You can use user libraries (downloads, documents) for storing the data (after allowing an access in appxmanifest file) or application data store (more viable in your case). Try to define DBName as

string DBName = ApplicationData.Current.LocalFolder.Path + @"\data.sqlite";

Or you can allow broadFileSystemAccess using link above

Sign up to request clarification or add additional context in comments.

2 Comments

The default working directory is the install location, which is read - only. Also be sure to check the SQLite docs re: temp directory.
Sorry for answering so late, I've been quite busy. Anyway, your help was extreamely usefull, thanks a lot!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.