首页 > 编程 > .NET > 正文

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

2024-07-10 13:12:58
字体:
来源:转载
供稿:网友

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

最大的网站源码资源下载站,

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表