Quantcast
Channel: Visual Studio and Visual Web Developer Express
Viewing all articles
Browse latest Browse all 3509

Backup database with OleDBCommand not working

$
0
0

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?


Viewing all articles
Browse latest Browse all 3509

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>