Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
3.86/5 (4 votes)
See more:
Hello guys,
i have a problem,too many guys couldn't solve it,i created a project and created a datagridview,in it i created a database file(MDF),and i used linq to write and read,like updating,deleting and adding records to my database,at last my project is finished but ,when i create a setup for it,after installing sql server 2008,.net client profile,... when i run my app and try to update it,it says database is readonly.i don't have this problem in debugor release mode,can anyone help me?i'm putting too much time to solve this problem.
Posted
Updated 4-Mar-20 5:23am
Comments
Pablo Aliskevicius 9-Apr-12 8:07am    
Is the .mdf file, on disk, actually read only? This could be so if the file was read only when you packed your installer. For instance, if your .mdf file is under source control, and you checked it in before packing your installer.
F.moghaddampoor 9-Apr-12 8:44am    
Hello Pablo,
I checked the file attributes ,but its not readonly.
F.moghaddampoor 9-Apr-12 8:44am    
and thanks for ur answer
F.moghaddampoor 9-Apr-12 8:45am    
how can i take my files out of source control then?
F.moghaddampoor 9-Apr-12 9:12am    
I just hesitate about your answer and went and after release mode,i debuged my code and then i copied release files to another folder,when i wanted to create setup i used the second folder,but still i have that error,readonly error.

1 solution

You're database file is in %ProgramFiles%. It should be in %AppData%

Piet
 
Share this answer
 
Comments
F.moghaddampoor 9-Apr-12 13:21pm    
Hello pietvredeveld,can i ask you how can i put my database in AppData,when end user decide the app directory.
majune 10-Apr-12 10:46am    
two way:
1.modify the setup project.
when you make the setup,you should specify the path of f.mdf,ensure that the file will install into AppData folder.
2.copy f.mdf to AppData folder by app.
every time you run you app,the first thing is to copy the file to AppData folder,
you can add the follow code in your Main(or init) method and try again:
-----------------------------------------------------------------------------------
string sourcePath=@"C:\PROGRAM FILES\DEFAULT COMPANY NAME\SETUPER2";
string appDataPath= Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string fileName="F.MDF";
System.IO.File.Copy(sourcePath+"\\"+fileName, appDataPath+"\\"+fileName ,false);
----------------------------------------------------------------------------------
*1 is better.
F.moghaddampoor 17-Jan-13 9:15am    
This is it. The answer is correct. Thank you very much. :)
F.moghaddampoor 10-Apr-12 10:50am    
i'm really thanksful majune.i will try this.
member60 11-Apr-12 6:41am    
my 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900