Dim c md As New SQLCommand
c md.ConnectionName = y
c md.CommandText = "backup database 数据库名称 To disk = 'c:\备份.bak'"
c md.ExecuteNonQuery
msgbox("数据备份成功!")
还原代码:
Dim c md0 As New SQLCommand
c md0.ConnectionName = y
c md0.CommandText = "ALTER DATABASE [数据库名称] SET SINGLE_USER With ROLLBACK IMMEDIATE"
c md0.ExecuteNonQuery
Dim c md As New SQLCommand
c md.ConnectionName = y
c md.CommandText = "restore database 数据库名称 from disk = 'c:\ 备份.bak' WITH REPLACE "
c md.ExecuteNonQuery
Dim c md2 As New SQLCommand
c md2.ConnectionName = y
c md2.CommandText = "s elect * from sys.databases where name = '数据库名称'"
If c md2.ExecuteScalar = “数据库名称“” Then
msgbox("数据还原成功!")
End If