0

When I run my app from the project folder in bin\debug or bin\release, it works fine. Everything as well as my database works fine.

But when I create a setup file with my debug or release files my database doesn't work. I set my database connection like:

SqlCeConnection compact_con = new SqlCeConnection(@"Data Source=" + Directory.GetCurrentDirectory() + @"\chondrokotha.dat;Password=4545;");

and keeps the chondrokotha.dat in the debug folder.

My files look like this:

enter image description here

after that i put the database into a folder named chonrokotha. in this time error shows like

enter image description here

How can I solve this problem during creation of a setup file?

ImonBayazid
  • 1,066
  • 3
  • 16
  • 41
  • But when i copy my files into another file then run the app in that case database works fine. – ImonBayazid May 11 '13 at 10:19
  • I updated my question showing the error.please check it?? – ImonBayazid May 11 '13 at 10:37
  • Well, OK - that's a first step. So it seems to be an **access permission** problem - the file **is found** - but in the `C:\program files` directory, your current user obviously doesn't have permissions to **write** back to the database file! Try to put your database file elsewhere - under `C:\temp` or better yet: into [Isolated Storage](http://msdn.microsoft.com/en-us/library/3ak841sy%28v=vs.80%29.aspx) of .NET – marc_s May 11 '13 at 10:40
  • But all files including database are in the C:\program files.by the way, how can i solve this?? – ImonBayazid May 11 '13 at 10:41

1 Answers1

0

Based on your error message, it's clear that your current user executing your application doesn't have write permissions into the folder where your database file resides. This is the default on Windows Vista (I believe) and higher - by default, normal (non elevated users) don't have write permissions in C:\program files (and that's a good thing overall).

You can solve this several ways:

  • put the database file into a folder where the user can write to, e.g. C:\tmp or somewhere under C:\Users\(username)\.....

  • put the database file into Isolated Storage - a .NET mechanism that gives you folders where you are guaranteed that the user can write to

  • create a subfolder under your program folder and give your user (or Everyone) write permission to that folder

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • in 3rd option have i give the write permission to the folder for user(everyone) in my program(in my code).if so how can i do that??? – ImonBayazid May 11 '13 at 10:54
  • @DarkenShooter: **research!!!** You do know Google, right? Search for `visual studio setup add permissions to folder` or something like that, and then look at the articles you get.... [e.g. this other SO question here](http://stackoverflow.com/questions/4719224/visual-studio-installer-project-setting-file-permission) – marc_s May 11 '13 at 10:56