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

WoF_Angel picture WoF_Angel · Sep 5, 2010 · Viewed 23.6k times · Source

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

Answer

Payman picture Payman · Mar 14, 2011

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.