Private Sub Button_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ButtonClick 备份数据库 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) cnOpen() cmExecuteNonQuery() MsgBox(备份成功) cnClose()
End Sub
恢复 Private Sub Button_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ButtonClick Dim cn As New SqlConnection Dim cn As New SqlConnection Dim mydr As SqlDataReader Dim str As String
Dim tmpConnectionString As String = Data Source=JJK;Initial Catalog=master;Integrated Security=True cnConnectionString = tmpConnectionString cnConnectionString = tmpConnectionString cnOpen() cnOpen() Dim cm As SqlCommand = New SqlCommand(select spid from mastersysprocesses where dbid=db_id(JXbase) cn) mydr = cmExecuteReader()
Dim cm As SqlCommand = New SqlCommand() cmConnection = cn
While (mydrRead()) 杀死进程
str = kill & mydr(spid)ToString() cmCommandText = str cmCommandType = CommandTypeText ApplicationDoEvents() cmExecuteNonQuery() 杀进程 End While mydrClose() cm = New SqlCommand(RESTORE DATABASE JXbase FROM DISK=C:\Backup cn) 恢复备份 cmExecuteNonQuery() MsgBox(恢复成功成功) cnClose() cnClose()
End Sub