c# - WPF - How to Backup / Restore LocalDB Programmatically - ClickOnce -


i have application uses ef , localdb it's database, published clickonce. it's first time using localdb , don't know how can add feature application backup/restore database programmatically.

my app path installed clickonce :

c:\users\mahdi rashidi\appdata\local\apps\2.0\nol11tlw.9xg\czm702aq.lpp\basu..tion_939730333fb6fcc8_0001.0002_fd707bbb3c97f8d3 

and location database files installed :

c:\users\mahdi rashidi\appdata\local\apps\2.0\nol11tlw.9xg\czm702aq.lpp\basu...exe_939730333fb6fcc8_0001.0002_none_8c555c3966727e7f 
  1. how should backup/restore database?
  2. how can keep database safe clickonce further updates?

thanks alot :)

this did backup , restore of localdb

public void backupdatabase(string filepath)     {         using (tvend2014entities dbentities = new tvend2014entities(basedata.connectionstring))         {             string backupquery = @"backup database ""{0}"" disk = n'{1}'";             backupquery = string.format(backupquery, "full databsase file path c:\tempdb.mdf", filepath);             dbentities.database.sqlquery<object>(backupquery).tolist().firstordefault();         }     }      public void restoredatabase(string filepath)     {         using (tvend2014entities dbentities = new tvend2014entities(basedata.connectionstring))         {             string restorequery = @"use [master];                                                  alter database ""{0}"" set single_user rollback immediate;                                                 restore database ""{0}"" disk='{1}' replace;                                                 alter database ""{0}"" set multi_user;";             restorequery = string.format(restorequery, "full db file path", filepath);             var list = dbentities.database.sqlquery<object>(restorequery).tolist();             var resut = list.firstordefault();         }     } 

hope want.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -