Solved

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

Posted on 2011-09-23
12
1,838 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

757 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

21 Experts available now in Live!

Get 1:1 Help Now