Access is denied error

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
russelle
Posts: 9
Joined: Sat 16 Mar 2013 22:27

Access is denied error

Post by russelle » Tue 19 Mar 2013 22:17

I have this code in a Windows Store app to test if I'm connecting properly to my SQLite database:
NPDDataContext db = new NPDDataContext(@"Data Source=""J:\Software Development\NonProfitDemographics\NonProfitDemographics.UI\Data\NonProfitDemographics.db""");
Table<Household> Households = db.GetTable<Household>();
var LittletonHouseholds = from c in db.Households
where c.City == "Littleton"
select c;
foreach (var comp in LittletonHouseholds)
{
var messageDialog = new MessageDialog(comp.AddressLine1 + ", " + comp.City, "Household found!");
messageDialog.Commands.Add(new UICommand("OK"));
await messageDialog.ShowAsync();
}

and I seem to be getting an Access Denied error message in opening the database file. The error occurs on the foreach statement. The file is located in a Data folder within my Windows Store project. What am I missing? This is my first use of SQLite and LinqConnect.

Zero-G.
Posts: 398
Joined: Sat 09 Dec 2006 12:20

Re: Access is denied error

Post by Zero-G. » Wed 20 Mar 2013 12:44

Hey

What kind of Version do you use? - For Windows Store Application, you need the correct Driver, because Windows Store apps do not support "normal" ADO.NET Connections.

THX

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Access is denied error

Post by MariiaI » Wed 20 Mar 2013 13:29

This error is occurs because you create a DataContext object explicitly specifying the path to the database file:

Code: Select all

NPDDataContext db = new NPDDataContext(@"Data Source=""J:\Software Development\NonProfitDemographics\NonProfitDemographics.UI\Data\NonProfitDemographics.db""");
Windows Store applications have very restricted access to the file system (arbitrary folder of the file system can not be used directly).

Please use one of the following ways:
1) create database in the LocalFolder (ApplicationData.Current.LocalFolder) using CreateDatabaseAsync method or copy it from your location using CopyAsync method (described in the Samples).
2) created DataContext object with full path to the database file in this format:

Code: Select all

string fullPath = "Data Source=" + Path.Combine(
      ApplicationData.Current.LocalFolder.Path, dbName);
  NPDDataContext db = new NPDDataContext(fullPath);
These ways are described in LinqConnect for Metro quick start guide at
http://blogs.devart.com/dotconnect/linq ... guide.html

Also, please see LinqConnect for Metro samples, which are included in the installation package.

russelle
Posts: 9
Joined: Sat 16 Mar 2013 22:27

Re: Access is denied error

Post by russelle » Wed 20 Mar 2013 18:17

Okay, I understand what you're saying, but exactly where should the database file physically reside? If I look in my Users directory under my user name I see c:\Users\Russell Eubanks has a hidden AppData directory and a shortcut to Application Data. I cannot access the Application Data shortcut, but the AppData directory has Local, LocalLow and Roaming subdirectories. I tried putting my database file directly into that Local folder and using
public static NPDDataContext db = new NPDDataContext("Data Source=ms-appdata:///local/NonProfitDemographics.db");
to point to the database file, but got a File Not Found error.
The Quick Start Guide shows a DeployDatabase method, but I cannot find it in the downloaded code. It uses a StorageFile object, which I cannot find anywhere.
Assuming I include my database file in the project and set its Build Action to Content, must I CopyAsync the file to ApplicationData.Current.LocalFolder everytime I want to use it?
I must say Devart's guidance on this essential functionality is a little vague.
Thanks for your assistance.

russelle
Posts: 9
Joined: Sat 16 Mar 2013 22:27

Re: Access is denied error

Post by russelle » Wed 20 Mar 2013 18:18

I am using LinqConnect to Metro.

russelle
Posts: 9
Joined: Sat 16 Mar 2013 22:27

Re: Access is denied error

Post by russelle » Wed 20 Mar 2013 18:52

When I look at the Quick Start example (TaskList), I see in the Model folder the class TaskListDatabase.cs. This class contains all kinds of methods like OnCreated() and Create(). When I created this class in my project I ended up with only a Create() method and a DefaultConnectionString property. It looks like the example inherits from some other class or interface. I am using a partial class with the same name as the database model. What am I missing?

russelle
Posts: 9
Joined: Sat 16 Mar 2013 22:27

Re: Access is denied error

Post by russelle » Wed 20 Mar 2013 18:55

Mariial,
Any way to contact you directly to hash this out? I'm using a trial version of LinqConnect to Metro and would like to get this working so I can purchase a license.
Thanks,
Russell

russelle
Posts: 9
Joined: Sat 16 Mar 2013 22:27

Re: Access is denied error

Post by russelle » Wed 20 Mar 2013 20:11

All I want to do is
(1) create a model from an existing SQLite file, and
(2) use that model and that existing file in my Windows Store app.
Seems pretty fundamental. Could you provide (tested) code for this? The Quick Start write-up is wholly inadequate.

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Access is denied error

Post by MariiaI » Thu 21 Mar 2013 12:03

I tried putting my database file directly into that Local folder
The CreateDatabaseAsync/CopyAsync methods create database file in the randomly generated folder in
'Users/User/AppData/Local/Packages' directory. Thus, you can't put the database file there manually.
Any way to contact you directly to hash this out?
We provide support for users on our forum or by e-mail.
must I CopyAsync the file to ApplicationData.Current.LocalFolder everytime I want to use it?
No you don't, in case the database file has been created there once, there is no need to do it again.

Quick start guide provides general information for starting work with LinqConnect for Metro. Fully functional application demonstrating how to work with database files and DataContext objects comes with install package. The LinqConnect for Metro samples "Mini Notes" are available in the 'C:\Program Files (x86)\Devart\dotConnect\Linq\Samples\LinqConnect\Metro' directory after installation of the product (in case the "Samples" component has been selected).

We are sending you a small test project and Samples to the e-mail address you provided in your forum profile, please check that the letter is not blocked by your mail filter.
Please tell us if this helps.

Post Reply