Private Sub cmdOk_Click()
    Dim cPMasterConn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim mSqlMaster As String, rq As String, s2 As String
    
    rq = Format(Date, "yyyymmdd") & Format(Time, "hhmm")
    
'    mSqlMaster = "provider=SQLOLEDB;server=" & HostName & ";database=master;uid=" & ConnectUserName & ";pwd=" & ConnectPassWord
    mSqlMaster = "provider=SQLOLEDB;server=" & HostName & ";database=master;uid=sa;pwd=11"
    cPMasterConn.CursorLocation = adUseClient
    cPMasterConn.CommandTimeout = 0
    
    cPMasterConn.Open mSqlMaster
    
    If MsgBox("您确认要备份数据吗（Y/N）？", vbYesNo + vbQuestion + vbDefaultButton2, "提示") = 7 Then Exit Sub
    
    Me.MousePointer = vbHourglass
    
    Set rs = cPMasterConn.Execute("Select * From Master.Dbo.SysDevices Where Name='成绩数据库" & rq & "备份'")
    If rs.RecordCount = 0 Then
        cPMasterConn.Execute "sp_addumpdevice 'Disk', '成绩数据库" & rq & "备份','E:\成绩数据库" & rq & "备份'"
    End If
    rs.Close
  
    cPMasterConn.Execute "BACKUP DATABASE 教学成绩管理数据库 TO 成绩数据库" & rq & "备份"
    
    Me.MousePointer = vbDefault
    MsgBox "数据备份完毕！", vbInformation, "提示"
    cPMasterConn.Close
    cmdOk.Enabled = False
End Sub

