我正在使用以下代码表,复制/更新数据库。
Public Sub backupData()
Try
Dim s As StreamWriter
Dim portfolioPath As String = Environment.CurrentDirectory
MsgBox(Application.UserAppDataPath)
If Not Directory.Exists(LIC.My.Settings.BackupDirectory) Then
Directory.CreateDirectory(LIC.My.Settings.BackupDirectory)
File.Create(LIC.My.Settings.BackupDirectory & "LIC.Mdf").Close()
File.Create(LIC.My.Settings.BackupDirectory & "Backup log.rtf").Close()
s = New StreamWriter(LIC.My.Settings.BackupDirectory & "Backup log.rtf", True)
s.WriteLine("This backup was initially taken on - " & Date.Now)
s.Flush()
s.Close()
FileCopy(portfolioPath & "LIC.mdf", LIC.My.Settings.BackupDirectory & "LIC.Mdf")
s = New StreamWriter(LIC.My.Settings.BackupDirectory & "Backup log.rtf", True)
MsgBox("New directory and backup file created")
Else
FileCopy(portfolioPath & "LIC.mdf", LIC.My.Settings.BackupDirectory & "LIC.Mdf")
s = New StreamWriter(LIC.My.Settings.BackupDirectory & "Backup log.rtf", True)
s.WriteLine("This backup was latest updated on - " & Date.Now)
s.Flush()
s.Close()
MsgBox("Back up completed successfully")
End If
Catch ex As Exception
Dim MessageString As String = "Report this error to the system administrator: " & ControlChars.NewLine & ex.Message
Dim TitleString As String = "Data Backup Failed"
MessageBox.Show(MessageString, TitleString, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
But i get an error *"The Process Cannot Access The File Because It Is Being Used By Another Process"*Any Idea How Can I Copy/Backup The Files??