locked
Access denied when trying to open a database file in the app's local folder RRS feed

  • Question

  • I am trying to put a copy of the database file used by my app, on OneDrive to allow syncing of data across multiple devices. When I try to open the db file to read it, an "Access denied" exception is thrown. Here is the code that's failing:

    var stream = await ApplicationData.Current.LocalFolder.OpenStreamForReadAsync(dbFile)

    This code also fails with the same error:

    var files = await ApplicationData.Current.LocalFolder.GetFilesAsync()

    So it appears that it may be access to the LocalFolder that's being denied.

    Friday, July 8, 2016 5:55 AM

Answers

  • It turns out that my database file probably needed to be freed or released. I access it using the MobileServiceClient API. When I called Dispose() I was then able to open the db file. The first time I got the OpenStreamForReadAsync() to work I was able copy the file to OneDrive, but now every time I call it the stream has a length of 0 so my subsequent PutAsync() call puts a zero length file on OneDrive. Not sure why that's happening but I guess that's another topic.
    • Marked as answer by AZ Apps Friday, July 22, 2016 1:19 AM
    Friday, July 22, 2016 1:19 AM

All replies

  • Hello AZ Apps,

    Welcome to the Developing Universal Windows apps forum! 

    Please read the sticky posts, especially the Guide to posting: subject line tags and Known Issues for Windows 10 SDK and Tools .

    Based on MSDN File access permissions, we can know that we have the following way to access local folder:

    1. LocalFolder.GetFilesAsync

    2. URI

    From your code it seems your code is alright. Can you give us more details? For example, a complete sample or code around your getfile. I've tested with a simple code like ApplicationData.Current.LocalFolder.GetFilesAsync it works without problem.

    Best regards,

    Barry


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Barry Wang Thursday, July 21, 2016 8:20 AM
    Monday, July 11, 2016 6:20 AM
  • It turns out that my database file probably needed to be freed or released. I access it using the MobileServiceClient API. When I called Dispose() I was then able to open the db file. The first time I got the OpenStreamForReadAsync() to work I was able copy the file to OneDrive, but now every time I call it the stream has a length of 0 so my subsequent PutAsync() call puts a zero length file on OneDrive. Not sure why that's happening but I guess that's another topic.
    • Marked as answer by AZ Apps Friday, July 22, 2016 1:19 AM
    Friday, July 22, 2016 1:19 AM