Solved

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

Posted on 2011-09-23
12
1,937 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 

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
 

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

820 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