Chinaunix首页 | 论坛 | 博客
  • 博客访问: 743975
  • 博文数量: 769
  • 博客积分: 6000
  • 博客等级: 准将
  • 技术积分: 4985
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-15 16:37
文章分类

全部博文(769)

文章存档

2011年(1)

2008年(768)

我的朋友

分类:

2008-10-15 16:38:30

  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

【责编:Luzi】

--------------------next---------------------

阅读(333) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~