This is a bug in your code, you are using a relative filename instead of a full path. In other words, "db.db"
instead of "c:\foo\bar\db.db"
. You'll now have a big dependency on the default directory of the program. This will work just fine in Visual Studio when you debug and test your app, the default directory will be the bin\debug directory of your project. You'll have no trouble writing to that directory.
But will not work when your program is launched by Windows, the default directory of your program will now be the default Windows directory, c:\windows\system32. Programs do not have write access to that directory, it is protected by UAC.
Fix the bug by specifying the full path to the file. You'll want to use Environment.GetFolderPath() to obtain a good directory, that should almost always be SpecialFolder.ApplicationData
. Use the Path.Combine() helper method to construct the path.