Question

I have actually gone through stackoverflow answers for the same question asked before. I understood that this problem is being caused because of restricted permission in Program Files folder.

I have gone through this answer at https://stackoverflow.com/a/5714111/1182021, and the same solution is being all over the web

If the MDB file is in your application path, then the default permissions would require elevation of rights to be able to write to the files -- I'd recommend moving the data to the ApplicationData shared folder, where end users will have write permissions by default

My query is in continuation to the above solution only:

I have globally changed my database path to Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)) and from there I wish to access my database as it will be a public access folder (I surfed and came to this conclusion)

  1. How to define this while deploying the application? Means when I am deploying my Setup and Deployment project it automatically puts my database files in my C:\Program Files\MyApplication\ and so my application is not able to access the database at the ApplicationData folder.
  2. Secondly, is this the only way? Can't I get my database into my installed directory and give full permission to my application to access my DB?

I have definitely read TomTom answer at https://stackoverflow.com/a/14611895/1182021 but still if any trick that can do and which is feasible and advisable.

Was it helpful?

Solution

Okay I dont know why I didn't got any answers yet. Was really trying to fix this issue and finally found the solution.

On your Database global configuration file that you have created within your project to manage all your database related work like add, delete, update and connection. For a local database define a LocalDbPath like this:

public string LocalDBPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

Then use the same LocalDBPath everywhere in your database connection.

While deploying the project via Setup and Deployment go to:

  1. File System Editor
  2. Right Click on File System on Target Machine
  3. Select Add Special Folder
  4. Select User's Application Data Folder
  5. And Add your Database file by going into User's Application Data Folder -> Right Click Add -> File and choose the file.

Build your solution and you are good to go. Cheers!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top