How to backup Sql Database Programmatically in C#

user1287692 picture user1287692 · Mar 23, 2012 · Viewed 112.5k times · Source

I want to write a code to backup my Sql Server 2008 Database using C# in .Net 4 FrameWork. Can anyone help in this.

Answer

Davide Piras picture Davide Piras · Mar 23, 2012

you can connect to the database using SqlConnection and SqlCommand and execute the following command text for example:

BACKUP DATABASE [MyDatabase] TO  DISK = 'C:\....\MyDatabase.bak'

See here for examples.