Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Compact Edition 3.5 - Access to the database file is not allowed

I developed an application (100% local, no access to servers) using SQL Server Compact 3.5, and it works fine on my computer. However, when I deployed it on another computer, it shows this error:

Access to the database file is not allowed. [ File name = data\BDApepucCE.sdf ]

I deployed on a Windows XP computer. It shows this error whenever I try to write on the database, however, it works when I read.

I did a test on a Windows 7 computer, and it worked 100%, except when the file was accessed through the homegroup (that is, local network), on which it failed on both read/write.

Platform: Windows 7, Visual Studio 2010, and .NET 4 Client Profile

like image 855
WoF_Angel Avatar asked Sep 05 '10 20:09

WoF_Angel


3 Answers

Make sure you use |DataDirectory| in your connection string. Here is an example

connectionString="Data Source=|DataDirectory|MyDB.sdf"

I had the exact same problem ay you and I managed to fix it by adding the |DataDirectory| to my connection string.

Good luck.

like image 150
Payman Avatar answered Oct 21 '22 16:10

Payman


This worked for me: http://solutionevangelist.com/community/discussion/20/access-to-the-database-file-is-not-allowed.-system.data.sqlserverce.sqlceexception/p1

It it usually a permissions issue. I give "Everyone" full permissions to the .sdf file in App_Data, either via the GUI, or using

icacls database.sdf /grant Everyone:F
like image 16
Whiz Avatar answered Oct 21 '22 14:10

Whiz


I also had this same problem. My solution was in TFS/SourceControl at the time when I deployed it and the sdf file was checked-in (ie read-only) and this caused me the exact same error as above. When I checked out the sdf file and deployed again, everything was fine. Thought I'd share that in case other TFS users experience the same issue.

like image 9
Ghlouw Avatar answered Oct 21 '22 14:10

Ghlouw