0

I have a program created using c# which will resides at the c:\program files folder. I will get error if I am going to run this part

SQLiteConnection.CreateFile("db/MyDatabase.sqlite");

I already read about User Account Control thing here http://blogs.windows.com/windows/archive/b/developers/archive/2009/08/04/user-account-control-data-redirection.aspx but i really don't have any idea on how to do it..

My program will be in C:\program files\my program\db\MyDatabase.sqlite

user3258603
  • 149
  • 2
  • 17
  • Try and run your program as an admin. – Mehraban Apr 17 '14 at 13:27
  • i do.. but it I always get an error.. and it says something like "collecting error ..." – user3258603 Apr 17 '14 at 13:28
  • 2
    Why not use the folders Windows provides for that kind of stuff? %APPDATA% and Documents? – kat0r Apr 17 '14 at 13:30
  • What is the exact exception? Does the `db` subfolder already exist, and, if not, will SQLite automatically create any subfolders as necessary when creating the file? – Mike Guthrie Apr 17 '14 at 13:31
  • @kat0r so you mean it will become like this `C:\Users\Username\AppData\Local\VirtualStore\Program Files\my program\db\MyDatabase.sqlite` ? or i will replace Username with variable and others? – user3258603 Apr 17 '14 at 13:36
  • 3
    Instead of saying it says "something like" please copy and paste [the exact error message](http://blogs.msdn.com/b/saraford/archive/2008/08/07/did-you-know-you-can-copy-the-exception-details-with-one-click-from-the-exception-assistant-276.aspx) in to your question. – Scott Chamberlain Apr 17 '14 at 13:37
  • The usual way would be `C:\Users\Username\AppData\Local\YourCompanyName\ProgrammName\MyDatabase.sqlite`. But you do not need the special privileges to write there, that you would need to write to the ProgramFiles folder. – kat0r Apr 17 '14 at 13:38
  • @MikeGuthrie `db` sub folder doesn't exist.. if (!File.Exists("db//legal_dept.sqlite")) { SQLiteConnection.CreateFile("db/MyDatabase.sqlite"); } else { textBox1.Text = "Connected"; } – user3258603 Apr 17 '14 at 13:39
  • 2
    Program Files is the worst directory where to store data. http://stackoverflow.com/questions/5116911/where-to-store-application-data-in-windows-7-and-vista – Ondrej Svejdar Apr 17 '14 at 13:42
  • My Program has stop working Windows is collecting more information about this problem. This might take several minutes... @ScottChamberlain – user3258603 Apr 17 '14 at 13:43

1 Answers1

1

Try using the AppData folder - you should not save such stuff in ProgramFiles anyway:

var dir = Path.Combine(Environment
    .GetFolderPath(Environment.SpecialFolder.ApplicationData), "MyProgram");
if(!Directory.Exists(dir))
    Directory.CreateDirectory(dir);
SQLiteConnection.CreateFile(Path.Combine(dir, "MyDatabase.sqlite"));
Christoph Fink
  • 22,727
  • 9
  • 68
  • 113