Reputation: 3025
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)
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.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.
Upvotes: 0
Views: 1248
Reputation: 3025
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:
File System Editor
File System on Target Machine
Add Special Folder
User's Application Data Folder
User's Application Data Folder
-> Right Click Add
-> File
and choose the file.Build your solution and you are good to go. Cheers!
Upvotes: 1