WoF_Angel WoF_Angel - 1 year ago 230
SQL Question

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download