1
votes

I have developed a desktop application in C# with Microsoft SQL Server Compact Edition 3.5.

It works fine when I run .exe file from solution folder (bin\release or debug) but when I tried to deploy it by creating its setup it shows unhandled exception:

You don't have permission to access CustomersDB.sdf file.

Note there is no path error it is correct.

string lokasifile = Environment.CurrentDirectory + "\\CustomersDB.sdf";
string stringkoneksi = "Data Source = \"" + lokasifile + "\"";
SqlCeConnection koneksi = new SqlCeConnection(stringkoneksi);
koneksi.Open();
1
As I see permission error, I immediately think of running it as an administrator or moving your file to some other place. Quite not sure if it'd work, but there's nothing bad in trying after all... :D - D. Petrov
The account running the website in the app pool does not have rights to the sdf file. Give it rights to that file. Alternatively, that file doesn't exist where you think it is. You should be using App_Data and |DataDirectory|, anyhow. If you did that, it would work as expected all the time, no worries. - user1228
SQL CE doesn't allow multiple concurrent connection at once btw. - Yogesh

1 Answers

0
votes
SecurityException 

This is nothing but caller does not have the appropriate permission. Environment.CurrentDirectory Property

try
{
     //Call Path here you will get to what the exactly error is
}
catch (Exception ex)
{
     if (ex is DirectoryNotFoundException|| ex is IOException|| ex is SecurityException)
     {
          //Your handling here
     }
     else
     {
          throw;
     }
}