4

This message appears every time I try to save the data to the DB.

Failed to update database because the database is read only

Note: This error comes only when the application is installed to C drive.

Front End: VB.NET

Back End:SQL Server

Is there any way to overcome this issue? Or any way to restrict the user from installing the application on C drive?

slayernoah
  • 4,382
  • 11
  • 42
  • 73
Pooh
  • 105
  • 1
  • 3
  • 12
  • What is your OS? Where on C: drive is it installed? – PM 77-1 Dec 26 '13 at 21:39
  • Windows 7 installed to C: – Pooh Dec 26 '13 at 21:49
  • I'm not sure what is going on here but this looks like a sql error and not an operating system error. In other words, it's probably not related to your "C" drive (I doubt your C drive is in "read-only"). Try running this... exec sp_dboption 'databasename','read only' – sam yi Dec 26 '13 at 21:50
  • i can do this.. but the user may nt know to do all these.. any idea why this happens like this? – Pooh Dec 26 '13 at 21:51
  • exec sp_dboption 'databasename','read only' allows you to check if the database is in "read-only" mode. If it is, you can set it to READ_WRITE... ALTER DATABASE database-name SET READ_WRITE WITH NO_WAIT – sam yi Dec 26 '13 at 22:03
  • http://stackoverflow.com/questions/2560381/failed-to-update-database-because-it-is-read-only, http://stackoverflow.com/questions/5713416/failed-to-update-mdf-database-because-the-database-is-read-only-windows-applic – rudi bruchez Dec 26 '13 at 22:06
  • Does your user have admin privileges? – PM 77-1 Dec 26 '13 at 22:08
  • yaa.. admin privileges r der.. – Pooh Dec 26 '13 at 22:16
  • @rudibruchez: ua link gave me a hint. n it worked. but every user after the installation should change the permission of the DB. its hectic for them.. they may not have that much knowledge. this application is standalone. any soution for this? any changes to b made to DB during deployment? – Pooh Dec 26 '13 at 22:37

1 Answers1

3

I would check the file system privileges. I suppose you talk about an SQL server file database. You receive the message because the account trying to access your file database does not have the file system permissions to do so.

  1. In order to confirm my suggestion, you allow everyone to access the specific directory with full permissions.

  2. Then, you have to check what is the account trying to do the actual access. Probably it's a system account (user ASPNET or NETWORK SERVICE). You have to give the respective permissions to the specific account.

  3. Then, restart IIS.

If you want to do this for a distributed stand-alone application. Then these permissions would have to change on each machine where the program would be installed. In order to avoid putting users in such a fuss, the setup program should do it. I am not an expert on setup programs, but even the simplest ones would give you the option to do it, after asking the system adminstrator's approval. I suppose you could build a custom action during the setup program which would change the specific folder's permissions, perhaps by using xcacls.exe.

Hope I helped!

Pantelis Natsiavas
  • 5,293
  • 5
  • 21
  • 36
  • yeah.. but every user after the installation should change the permission of the DB. its hectic for them.. they may not have that much knowledge. this application is standalone. – Pooh Dec 26 '13 at 22:36
  • Or perhaps your installation program could change the permissions, after asking the PC administrator's approval of course... – Pantelis Natsiavas Dec 26 '13 at 22:37
  • Glad to help anyway. Please, upvote the answer so that other users who bump on your question would know the solution... – Pantelis Natsiavas Dec 26 '13 at 22:38
  • installation program is vb setup project.. does it hve any solution to over come this problem? – Pooh Dec 26 '13 at 22:43
  • @PantelisNatsiavas when you say allow everyone to access the specific directory with full permissions, how do you do this? It's in SQL Server or File Explorer? Is there an association between the Windows users and SQL Server? – Denis G. Labrecque Jul 28 '23 at 16:31
  • I was referring to file system privileges – Pantelis Natsiavas Jul 31 '23 at 08:50