1

when i am install my application to client machine which have window 7 then give me error that db file don't have read or write permission.

how can i give permission to that file ?

i already read other solution that i should store the db file in shared directories which have read write permission for every user.

but i want to store my database file into my program files folder and want to give permission to that file so it can also work in window 7 .

thanks

EDITED :--

as now all of you suggesting to save the db files in shared folder so my new question is now

how to store .mdf file in shared folder when making setup in c#. what changes should i make in app config file. currently its storing program files in my application folder where my application don't have read write permission .

currently my mdf file is on root and my app config file have this line of code :

<add name="HotelReservationSystem.Properties.Settings.HotelReservationDBConnectionString"
      connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\HotelReservationDB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
      providerName="System.Data.SqlClient" />
rahularyansharma
  • 11,156
  • 18
  • 79
  • 135
  • 1
    There is no good reason to ever store information inside of the Program Files folder. That's why it's been made much more difficult in Windows Vista and later. The security risks make it completely unjustifiable. What, exactly, do you think is wrong with using a shared directory like everyone else? – Cody Gray - on strike Jan 29 '12 at 09:21
  • possible duplicate of [Does Windows 7 have the same problem as Vista?](http://stackoverflow.com/questions/5210575/does-windows-7-have-the-same-problem-as-vista) – Cody Gray - on strike Jan 29 '12 at 09:21
  • @CodyGray will you please suggest any link what should i have to change in my code or making setup to store db file in shared directory and changes in app.config file – rahularyansharma Jan 29 '12 at 09:30
  • I have no idea how you're doing it now, so how should I tell you what to change? Wherever you specified the path, change it to a different one. – Cody Gray - on strike Jan 29 '12 at 09:37
  • will u please come on chat so it will be easy for me to give u idea about all this . – rahularyansharma Jan 29 '12 at 09:40
  • No, I don't do chat. Update your question with the relevant information if you want people to help. – Cody Gray - on strike Jan 29 '12 at 09:41

1 Answers1

0

Unfortunately after Windows XP this is NOT possible. In order for a user to write to anything in Program Files they need Administrator access. Not only do they need Administrator access but they also need UAC permission.

So you have to options

  1. Place the database in a read/write folder like ApplicationData
  2. Make your app run as admin UAC rights by adding the setting in app.manifest
MyKuLLSKI
  • 5,285
  • 3
  • 20
  • 39
  • have u any link which is related to making a setup in vs2010 with mdf file for window xp window7 – rahularyansharma Jan 29 '12 at 09:15
  • or how can i place my mdf file in those folder ? as i just add these files in my setup project by adding the files option – rahularyansharma Jan 29 '12 at 09:16
  • Nothing unfortunate. Unless you are a programmer thinking following specs is stupid - this was changed way before XP. Dumbo programmer ignroed it. There is a specific folder for that. – TomTom Jan 29 '12 at 10:17
  • @TomTom I only programmed AFTER XP so I only assumed you could do this (and no I do not test my apps under XP, because you should really stop using XP in this lifetime). I just been accustom to placing things is UAC safe places – MyKuLLSKI Jan 29 '12 at 16:21
  • @rahularyansharma I use INNO installer or Installshield and I set up the database path in there – MyKuLLSKI Jan 29 '12 at 16:22
  • @MyKuLLSKI hello sir i installed the install shield wizard for vs2010 but there is no option to set up the database path – rahularyansharma Jan 29 '12 at 16:36
  • @rahularyansharma I'm not sure what db you using but Google is your friend. You should mark this as an answer and ask a new question or search the web... http://www.installsite.org/pages/en/isp_db.htm – MyKuLLSKI Jan 29 '12 at 17:05
  • Switch over to WIX and learn what you are doing there (windows installer is not a "i have no clue and click around" technology unless you want to get into serious trouble - some reading is warranted). – TomTom Jan 29 '12 at 20:37