?
Solved

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

Posted on 2011-09-23
12
Medium Priority
?
2,078 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

718 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