Solved

SQL CE 4 - Access to the database file is not allowed

Posted on 2011-09-23
12
1,874 Views
Last Modified: 2016-09-14
Hello All.

I am recieving the following error message with my Windows Forms App when trying to access the SQL CE 4 App that I copied to CommonAppDataPath:
"Access to the database file is not allowed. [ 1884, File Name = C:\\ProgramData\\Company Name\\Program Name\\1.0.0.0\\database.sdf, SeCreateFile]."

I'm not sure how to go about solving this. The searches that I have done always lead me to ASP.NET implementations and issues with GoDaddy but this is a local Windows Forms App.
0
Comment
Question by:Dragonseer
  • 6
  • 5
12 Comments
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 36590061
Hi. Does it work if you use a different path other than ProgramData. i.e., try C:\Temp or some directory with full permissions. I suspect it is something to do with NTFS permissions on that directory.
0
 

Author Comment

by:Dragonseer
ID: 36590085
It does work with other directories but I am trying to follow proper standards by using the CommonAppDataPath folder since this is a program that will have many versions and constant updates, I want to install to this specific folder so that I will constantly know the local of the file and the user won't have direct access to it so they don't mess with it accidentally.

How can I give the file the appropriate permission?
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 36590135
Let me test to verify that. I happen to be re-installing my setup with Visual Studio and SQL Compact Edition 4. Web Platform Installer at work as we speak. *smile* How did the file get created in the first place? Did you do this via VS or was this a test deployment of your application? If file was marked as security risk, you can right-click and in properties select "Unblock" and see if that helps until I am able to test.
0
 

Author Comment

by:Dragonseer
ID: 36590165
Awesome, thank you.
The SQL CE Database was created via VS and the file is not being seen as a security risk.
0
 

Author Comment

by:Dragonseer
ID: 36590169
Also note, this issue does not come up on my local Windows 7 Development machine. It comes up on my test machines, Win 7, Vista and XP.
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 36590275
So, the it is once you deploy your application for testing. Okay, I will try. Possibly, the deployment is not installing something correctly; however, it sounds like the file was not marked as blocked. Did you already check what NTFS permissions it assigned the file? And that it is not flagged as Read Only.
0
Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Author Comment

by:Dragonseer
ID: 36590282
It did appear to be marked read only. Once I unchecked it, the program ran fine.

This leads to a new issue: how do I progamatically uncheck read only on this file so my application can access it?
0
 

Author Comment

by:Dragonseer
ID: 36590354
I tried toss in the below code before the connect function but it doesn't seem to have an effect.


 
if (File.GetAttributes(dataBaseFile) == FileAttributes.ReadOnly)
                    File.SetAttributes(dataBaseFile, FileAttributes.Normal);

Open in new window

0
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 36590391
Think you need to use RemoveAttribute with FileAttributes.ReadOnly.

http://msdn.microsoft.com/en-us/library/system.io.file.setattributes.aspx
http://msdn.microsoft.com/en-us/library/system.io.fileattributes.aspx

I am still fussing with my VS2010. *sigh* But that looks like it is a good approach.
0
 

Author Comment

by:Dragonseer
ID: 36590392
I figured it out. For some reason, my program doesn't see that it is read only so I skipped the check part down to only  File.SetAttributes(dataBaseFile, FileAttributes.Normal);

This appears to work, but I am testing it further.
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 36590421
Cool. Yes, I noticed after that RemoveAttribute was a custom function in the example specifically application to Hidden and Archive. ReadOnly should work from setting to Normal. Glad you found that.

Best regards and happy coding,

Kevin
0
 

Expert Comment

by:Member_2_6416305
ID: 41797418
In order for you to run the system, database is in program files folder. Make sure that you are running and program as administrator. This will solve your problem.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now