How to backup Sql Database Programmatically in C#

后端 未结 10 1889
说谎
说谎 2020-12-23 11:48

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

10条回答
  •  南笙
    南笙 (楼主)
    2020-12-23 12:13

    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.

提交回复
热议问题