编写了一下数据库备份代码:
Dim cn As Connection = Connections("SQL2008数据源")
Dim lx As Integer = cn.SourceType
If lx = 2 Then
Dim str As String = cn.ConnectionString
Dim mc As String
For Each s As String In str.split(";")
If s.StartsWith("Initial Catalog") Then
mc = s.split("=")(1)
End If
Next
计划在这添加一行判断服务器端是否存在“D:\屠宰分割成本核算系统数据备份”文件夹,如果不存在,提示用户添加此文件夹。
Dim bf As String = "D:\屠宰分割成本核算系统数据备份\"& format(Date.now,"yyyyMMddHHmmss") & ".bak"
Dim Result As DialogResult
Result = MessageBox.Show("是否现在【备份】数据库至服务器端【D:\屠宰分割成本核算系统数据备份】目录下 ?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If Result = DialogResult.Yes Then
Dim cmd As New SQLCommand
cmd.C
cmd.CommandText = "use master;BACKUP DATABASE " & mc & " TO DISK = '" & bf & "' With FORMAT,CHECKSUM;"
cmd.ExecuteNonQuery()
Dim dr As DataRow = DataTables("日志").AddNew()
dr("登录用户") = User.Name
dr("操作时间") = Now
dr("备份_路径") = bf
dr("备份_文件名") = format(Date.now,"yyyyMMddHHmmss") & ".bak"
dr("操作事项") = "数据备份"
DataTables("日志").Save()
计划在这添加一行判断服务器端是否存在“bf”文件,如果存在,提示备份成功信息。
Messagebox.Show("【备份】成功,保存到【" & bf & "】!","提示")
Else
Return
End If
Else
Messagebox.Show("非【SQL数据库】,请用其他方式备份!","提示")
End If
麻烦老师帮忙看一下,十分感谢!
[此贴子已经被作者于2019/10/21 15:15:59编辑过]