How to backup database (MS SQl Server 2008) in C# without using SMO (having proplems) ?

Posted by SzamDev on Stack Overflow See other posts from Stack Overflow or by SzamDev
Published on 2010-04-10T18:35:54Z Indexed on 2010/04/10 18:43 UTC
Read the original article Hit count: 487

Filed under:
|
|
|

Hi

I have this code and it is not working but I don't why?

try
        {
            saveFileDialog1.Filter = "SQL Server database backup files|*.bak";
        saveFileDialog1.Title = "Database Backup";
        if (saveFileDialog1.ShowDialog() == DialogResult.OK)
        {


            SqlCommand bu2 = new SqlCommand();
            SqlConnection s = new SqlConnection("Data Source=M1-PC;Initial Catalog=master;Integrated Security=True;Pooling=False");

            bu2.CommandText = String.Format("BACKUP DATABASE LA TO DISK='{0}'", saveFileDialog1.FileName);

            s.Open();

            bu2.ExecuteNonQuery();
            s.Close();
            MessageBox.Show("ok");

        }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }

and I get this error :

alt text

What is the proplem?

© Stack Overflow or respective owner

Related posts about c#

Related posts about database