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
From:http://tw.wingwit.com/Article/program/net/201311/12901.html