저는 Windows Store 응용 프로그램을 작성하고 있습니다. 일부 경우 (테스트, 새 사용자 등) 데이터베이스를 다시 만들어야합니다 - Sqlite가 사용되고 있습니다. 기존 데이터베이스를 백업하고 기존 데이터베이스를 삭제 한 다음 스키마가있는 새 데이터베이스 파일을 만들어야합니다. Windows 저장소 응용 프로그램에서 파일 삭제 - 액세스가 거부되었습니다. (HRESULT : 0x80070005 (E_ACCESSDENIED))
코드 : 나는 두 번 순차적으로 DB 파일이 첫 번째 호출 중에 생성되고 UnauthorizedAccessException 두 번째 통화 중에 그 삭제하는 동안 발생합니다) 방법 CreateDatabaseAsync를 (호출하는 경우public async Task<bool> CreateDatabaseAsync()
{
if (await PathUtils.FileExistsAsync(DbConstants.DbFileWithPath))
{
var currentDbFolder = await StorageFolder.GetFolderFromPathAsync(DbConstants.DbPath);
var currentdbFile = await StorageFile.GetFileFromPathAsync(DbConstants.DbFileWithPath);
await currentdbFile.CopyAsync(currentDbFolder, DbConstants.DbBackup, NameCollisionOption.ReplaceExisting);
//problem here with deletion
await currentdbFile.DeleteAsync(DbConstants.FilelDeletionOption);
}
return await CreateSchema();
}
private async Task<bool> CreateSchema()
{
var db = new SQLiteAsyncConnection(DbConstants.DbFileWithPath);
await db.CreateTablesAsync(typeof (Doc), typeof(DocAttachment));
db = null;
GC.Collect();
return true;
}
}
하기 - 주석 참조 . 나는이 파일을 열 수있는 것을 모른다. SQliteAsyncConnetion에 대한 참조를 null로 만들고 모든 세대의 컬렉션을 강제로 생성합니다. 그래도 파일을 삭제할 수 없습니다. { "액세스가 거부되었습니다 (HRESULT의 예외 : 0x80070005 (E_ACCESSDENIED))}.
ApplicationData.Current.LocalFolder.Path에서 파일을 만들고 있습니다.
현재 각 통합 테스트 중에 db를 다시 만들려고합니다.