c# - database not found after publish -


i make 1 project sql database , works without error in visual studio 2012 after publish , install it, when take backup shows below error

"database 'c:\users\lu\appdata\local\apps\2.0\d9hbhd8t.y1h\5b2jmg1t.n8w\game..tion_60f48512c0fd7b6a_0001.0000_7a5b2d8ced8c74c0\gamedata.mdf' not exist. make sure name entered correctly. backup database terminating abnormally."

here procedure

create proc dbackup @databasename sysname, @path nvarchar(400) backup database @databasename disk = @path init return 

here backup code:

private void button1_click(object sender, eventargs e) {   database db=new database();   try   {     db.connect();     sqlcommand ocommand = new sqlcommand(@"dbackup",db.sqlcon);     ocommand.commandtype = commandtype.storedprocedure;     ocommand.parameters.addwithvalue("@databasename", application.startuppath + "\\gamedata.mdf");     ocommand.parameters.addwithvalue("@path", textbox1.text);     ocommand.executenonquery();     messagebox.show("backup created sucessfully");   }   catch (exception ex)   {     messagebox.show("error occurd :" + ex.message);   }     {     db.disconnect();   }   this.close(); } 

do not use application.startuppath store database if deploying app clickonce.

it seems using localdb edition of sql server. there use correctly full name of file parameter backup database command.

but name of clickonce installation folder obfuscated, not work in sql statement.

you must copy .mdf file installation folder other local folder when application first launched after installation , use folder data.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -