Access is denied error
Access is denied error
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.
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.
Re: Access is denied error
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
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
Re: Access is denied error
This error is occurs because you create a DataContext object explicitly specifying the path to the database file:
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:
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.
Code: Select all
NPDDataContext db = new NPDDataContext(@"Data Source=""J:\Software Development\NonProfitDemographics\NonProfitDemographics.UI\Data\NonProfitDemographics.db""");
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);
http://blogs.devart.com/dotconnect/linq ... guide.html
Also, please see LinqConnect for Metro samples, which are included in the installation package.
Re: Access is denied error
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.
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.
Re: Access is denied error
I am using LinqConnect to Metro.
Re: Access is denied error
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?
Re: Access is denied error
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
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
Re: Access is denied error
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.
(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.
Re: Access is denied error
The CreateDatabaseAsync/CopyAsync methods create database file in the randomly generated folder inI tried putting my database file directly into that Local folder
'Users/User/AppData/Local/Packages' directory. Thus, you can't put the database file there manually.
We provide support for users on our forum or by e-mail.Any way to contact you directly to hash this out?
No you don't, in case the database file has been created there once, there is no need to do it again.must I CopyAsync the file to ApplicationData.Current.LocalFolder everytime I want to use it?
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.