Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-09-23
12
Medium Priority
?
2,130 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 60

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 60

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 60

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 60

Accepted Solution

by:
Kevin Cross earned 2000 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 60

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
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 extract information from SQL Server on Database, Connection and Server properties

886 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