To write in
Program files
folder you need to run your code as admin (with elevated privileges), even if you have the rights to write there. The VS debug folder is not protected this way. So you either force your app to be run with elevated privileges (
like described here[
^]), or you store your database elsewhere.
On the other hand, it might be the case, that path virtualization is active on that machine, and the files you try to save in a protected folder, are redirected to
AppData\Roaming[
^] or
Virtual Store[
^]for example.