VB.net实现sql数据库的备份与恢复

2009-05-12 22:32:30来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click '备份数据库 'BACKUP DATABASE Test TO DISK='C:\Backup' WITH Format Dim cn As SqlConnection Dim cm As SqlCommand cn = getDB() cm = New SqlCommand("BACKUP DATABASE JXbase TO DISK='C:\Backup ' WITH Format", cn) cn.Open() cm.ExecuteNonQuery() MsgBox("备份成功") cn.Close()

End Sub

'恢复 Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Dim cn As New SqlConnection Dim cn1 As New SqlConnection Dim mydr As SqlDataReader Dim str As String

 Dim tmpConnectionString As String = "Data Source=JJK;Initial Catalog=master;Integrated Security=True" cn.ConnectionString = tmpConnectionString cn1.ConnectionString = tmpConnectionString cn.Open() cn1.Open() Dim cm As SqlCommand = New SqlCommand("select spid from master..sysprocesses where dbid=db_id('JXbase')", cn) mydr = cm.ExecuteReader()

Dim cm1 As SqlCommand = New SqlCommand() cm1.Connection = cn1

While (mydr.Read()) '杀死进程

str = "kill " & mydr("spid").ToString() cm1.CommandText = str cm1.CommandType = CommandType.Text Application.DoEvents() cm1.ExecuteNonQuery() '杀进程 End While mydr.Close() cm = New SqlCommand("RESTORE DATABASE JXbase FROM DISK='C:\Backup'", cn) '恢复备份 cm.ExecuteNonQuery() MsgBox("恢复成功成功") cn.Close() cn1.Close()

End Sub

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:解决CSV字段数据带有双引号的问题

下一篇:.Net平台下开发中文语音应用程序

热门词条
热门标签