寻求vb.net数据库恢复源代码?

njhyh 2004-08-25 01:02:40
寻求vb.net数据库恢复源代码?我用windows继承联连接数据库的(Sql server2000)
...全文
137 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
njhyh 2004-08-26
  • 打赏
  • 举报
回复
谢谢!!我试试!!
yingshis 2004-08-26
  • 打赏
  • 举报
回复
up
cuiwb770111 2004-08-25
  • 打赏
  • 举报
回复
你可以试一下直接拼写SQL语句进行恢复数据库,例如:
Restore DataBase 所要恢复的数据库名 From Disk=数据库备份文件的完整路径名
zgczsf 2004-08-25
  • 打赏
  • 举报
回复
谢谢
chinahth 2004-08-25
  • 打赏
  • 举报
回复
terryxin 2004-08-25
  • 打赏
  • 举报
回复
自己试一下吧,应该可以的
PRivate Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim lpass As Boolean
If MsgBox("请确认是否恢复,恢复时会把原来的数据删除,请告知每个使用用户,请确认没有其他用户在使用系统!!!", MsgBoxStyle.OKCancel + MsgBoxStyle.Critical + MsgBoxStyle.DefaultButton2, "警告") <> MsgBoxResult.OK Then
Exit Sub
End If

If txt_BakPath.Text = "" Then
MsgBox("恢复路径不能为空!")
Exit Sub
End If

Dim trans As SqlTransaction
Dim Mycn As New SqlConnection() '("User ID=sa;password=;Initial Catalog=master;Data Source=LOCALHOST;")
Dim mycn1 As New SqlConnection()

Mycn = cn.GetCN
If Mycn.State = ConnectionState.Closed Then
Mycn.Open()
End If



' cn.GetCN.Close()
' mycn1.Close()

Dim sqlBP As New SqlCommand()
Dim sqlInset As New SqlCommand()

Try
With sqlBP
.Connection = Mycn
.CommandType = CommandType.Text

Shell("net stop mssqlserver", AppWinStyle.Hide, True, -1)
Shell("net start mssqlserver", AppWinStyle.Hide, True, -1)
.CommandText = " DROP DATABAS d2mrpii"
' .Connection = Mycn
'.CommandType = CommandType.Text
.ExecuteNonQuery()
.Connection = Mycn
.CommandType = CommandType.Text
.CommandText = " restore database d2mrpii from " & txt_SetName.Text ' & " with NORECOVERY"
.ExecuteNonQuery()
End With
MsgBox("恢复成功!")

lpass = True
If mycn1.State = ConnectionState.Closed Then
mycn1.Open()
End If

trans = mycn1.BeginTransaction
sqlInset.Transaction = trans
With sqlInset
.Connection = mycn1
.CommandType = CommandType.StoredProcedure
.CommandText = "Addt9_004"
.Parameters.Add("@baktype", SqlDbType.Char).Value = txt_BakType.Text & ""
.Parameters.Add("@bakpath", SqlDbType.NVarChar).Value = txt_BakPath.Text & ""
.Parameters.Add("@setname", SqlDbType.NVarChar).Value = txt_SetName.Text & ""
.Parameters.Add("@username", SqlDbType.NVarChar).Value = User_ID & ""
.Parameters.Add("@isres", SqlDbType.Bit).Value = 1
.Parameters.Add("@remark", SqlDbType.NVarChar).Value = txt_Remark.Text
.ExecuteNonQuery()
trans.Commit()
End With

dsRestore.Clear()
daRestore = New SqlDataAdapter("select * from t9_004 where status=1 order by bakdate desc", cn.GetCN)
daRestore.Fill(dsRestore, "t9_004")
DG1.DataSource = dsRestore
DG1.DataMember = "t9_004"

Catch e1 As SqlException
MsgBox("失败!" & Err.Description)
If lpass = True Then
trans.Rollback()
End If
End Try

16,722

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧