I just want to backup my database with the push of a button, but it isn't working because the SQL statement is invalid, but wherever on the internet i look people are doing it just like I am.
public partial class Form1 : Form { string conString = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString; OleDbConnection connection; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { connection = new OleDbConnection(conString); } private void btnBackup_Click(object sender, EventArgs e) { string backupString = "backup database databasename TO disk =' C:\\Users\\magnus.andersson3\\Documents\\Visual Studio 2013\\Projects\\testbackup\\testbackup\\backup.bak';"; OleDbCommand comBackup = new OleDbCommand(backupString, connection); connection.Open(); try { comBackup.ExecuteNonQuery(); //This isn't working } catch (OleDbException ex) { MessageBox.Show(ex.ToString()); } connection.Close(); } } }
the .ExecuteNonQuery() gives me an error
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.
So, any ideas for other ways i can do this?