vb.net

位置:IT落伍者 >> vb.net >> 浏览文章

使用VB.net实现sql数据库的备份与恢复代码


发布日期:2024年04月18日
 
使用VB.net实现sql数据库的备份与恢复代码

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

上一篇:用VB.NET设定当前工作路径

下一篇:使用VB.NET的五个技巧之处理数据行