Skip to content

Commit

Permalink
Merge pull request #21 from poizan42/drop-table-if-exists-pre-sqlserv…
Browse files Browse the repository at this point in the history
…er2016

Fix pre-SQL Server 2016 compatibility of "drop table if exists" when disposing temp tables.
  • Loading branch information
PawelGerr authored Apr 25, 2022
2 parents ba6c537 + 3cbb107 commit 3d8e3c8
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ public void Dispose()
if (!_dropTableOnDispose || _database.GetDbConnection().State != ConnectionState.Open)
return;

_database.ExecuteSqlRaw($"DROP TABLE IF EXISTS {_sqlGenerationHelper.DelimitIdentifier(Name)}");
_database.ExecuteSqlRaw($@"
IF(OBJECT_ID('tempdb..{Name}') IS NOT NULL)
DROP TABLE {_sqlGenerationHelper.DelimitIdentifier(Name)};
");
_database.CloseConnection();
}
catch (ObjectDisposedException ex)
Expand Down

0 comments on commit 3d8e3c8

Please sign in to comment.