1

Error when I press the button (Cannot open the backup device) but the location where I transfer the database is correct. how to have access to other folder.. because the default backup of sql my code is working to the default backup of microsoft..

C:\Users\orly.simbulan\Desktop\extracted

this is in my form load

try
{
SqlConnectionconn = newSqlConnection(connection);
conn.Open();
string sql_query="SELECT name from sys.databases WHERE name='Site5'";
SqlCommand cmd= newSqlCommand(sql_query,conn);
SqlDataReaderdr = cmd.ExecuteReader();
while(dr.Read())
{
listBox1.Items.Add(dr[0].ToString());
}

conn.Close();
}
catch(Exceptionex)
{
MessageBox.Show(ex.ToString());
}

in my button1

SqlConnectionconnec=newSqlConnection(connection);
connec.Open();
//MessageBox.Show(listBox1.SelectedItem.ToString());
stringlocation=@"C:\Users\orly.simbulan\Desktop\extracted";
stringsql="BACKUPDATABASE["+listBox1.SelectedItem.ToString()+"]TODISK='"+location+"\\"+"Database"+"-"+DateTime.Now.ToString("yyyy-MM-dd--HH-mm-ss")+".bak'";
SqlCommandcmd=newSqlCommand(sql,connec);
cmd.ExecuteNonQuery();
connec.Close();

This is the error... Back error when I click the button

Community
  • 1
  • 1
Dev George
  • 49
  • 13
  • possible duplicate of https://stackoverflow.com/questions/3960257/cannot-open-backup-device-operating-system-error-5 – ZiggZagg Apr 02 '18 at 08:39

0 Answers0