0

Hi there I developed an applicaiton that uses SQLlite database but after making setup project and installing it i get exceptions when writing to it

System.Data.SQLite.SQLiteException: Attempt to write a read-only database

what is the problem?

it works fine while developing at visual studio

EDIT I added user Everyone and assigned it all rights to the folder where the database is placed.that folder was created by the installer and it worked now but what should I do to avoid this ..........because where this application will be deployed they are not much computer literate to do this manually

Afnan Bashir
  • 7,319
  • 20
  • 76
  • 138
  • Where on the disk is the database located, exactly? – Tomalak Jun 03 '11 at 12:08
  • Have you checked the permission of the account used to ran the application? – OnesimusUnbound Jun 03 '11 at 12:09
  • in bin folder and when deployed then it is where exe is placed.i read data but cannot write – Afnan Bashir Jun 03 '11 at 12:10
  • I added user Everyone and assigned it all rights to the folder where the database is placed.that folder was created by the installer and it worked now but what should I do to avoid this ..........because where this application will be deployed they are not much computer literate to do this manually – Afnan Bashir Jun 03 '11 at 12:14

3 Answers3

2

Attempt to write a read-only database - System.Data.SQLite

Community
  • 1
  • 1
Farshid Zaker
  • 1,960
  • 2
  • 22
  • 39
  • I added user Everyone and assigned it all rights and it worked now but what should I do to avoid this ..........because where this application will be deployed they are not much computer literate to do this manually – Afnan Bashir Jun 03 '11 at 12:13
  • @Afnan try to reduce the right, granting [least privilege](http://en.wikipedia.org/wiki/Principle_of_least_privilege) – OnesimusUnbound Jun 03 '11 at 12:15
  • well if i grant least then same error will occur because it wont have permissions....rite? – Afnan Bashir Jun 03 '11 at 12:18
2

In the link forum, the common root cause is permission issue.

http://sqlite.phxsoftware.com/forums/p/864/7498.aspx

Update

Why not encrypt the sqlite database

Encrypt SQLite database in C#

Community
  • 1
  • 1
OnesimusUnbound
  • 2,886
  • 3
  • 30
  • 40
  • I added user Everyone and assigned it all rights to the folder where the database is placed.that folder was created by the installer and it worked now but what should I do to avoid this ..........because where this application will be deployed they are not much computer literate to do this manually – Afnan Bashir Jun 03 '11 at 12:16
  • Do you really expect the "computer illeterate" to tinker the sqlite database file? They would rather use the winform :-). Anyway, try to grant least privileges. – OnesimusUnbound Jun 03 '11 at 12:18
  • actually this application is used for data entry only and staff will do it.Anyway it would be great if you give me a link how to implement it?does it involve `System.Management.Instrumentation` – Afnan Bashir Jun 03 '11 at 12:22
  • Oh, nevermind, I've updated the post and suggest that you encrypt the database. – OnesimusUnbound Jun 03 '11 at 13:23
1

The database should not be in the same folder as the exe file. The location of exe files, i.e. program files, is protected for security reasons, and modifying the permissions is not the way to go.

You should put data that needs to be written to in the users data area, or the data area for all users.

You can locate this folder using SHGetSpecialFolderPath

David Sykes
  • 48,469
  • 17
  • 71
  • 80