EFCore を LocalDB (SQL Server Express) で動かした際、DB ファイルを消したいのにプロセスにロックされている場合

protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
var sql =
"declare @dbname varchar(max);"
+ "set @dbname = quotename(db_name());"
+ "exec('ALTER DATABASE ' + @dbname + ' SET OFFLINE WITH ROLLBACK IMMEDIATE;'); "
+ "exec('sp_detach_db ' + @dbname + ';'); ";
Context.Database.ExecuteSqlCommand(sql);
Context.Dispose();
}
disposedValue = true;
}
}

--

--

--

President of team Sirocco, LLC / Financal Technology を中心に、技術界隈を実務もやりつつ見続けてます。

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
arichika.taniguchi

arichika.taniguchi

President of team Sirocco, LLC / Financal Technology を中心に、技術界隈を実務もやりつつ見続けてます。

More from Medium

Build a REST API with ASP.NET Web API

WPF Custom Markup Extensions

Resolve mixed content SSL error with Apache Virtual Hosts — .NET 6.0