1
のI /コピーするバックアップデータベースプロセスは別のプロセスで使用されているためファイルにアクセスできません...どのような考えですか?
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
を次のコードスニペットを使用しています。しかし、私はエラーを取得*「別のプロセスによって使用されているため、プロセスはファイルにアクセスできません」*任意のアイデアどのようにすることができます私はファイルをコピー/バックアップしますか?
ファイルが見つかった場合は、そのファイルにアクセスできません。この場合の理由は、読んでいる間に変更される可能性があるためです。データベースをバックアップするには、手動でファイル – Mharlin
をコピーしようとするのではなく、SQL Server上でバックアップSQLスクリプトを実行する方が良いですか? – Jason
.mdfファイル...... –