예제 #1
0
        public void Dispose()
        {
            if (!_deleteDatabaseOnDispose)
            {
                return;
            }

            SqlConnection.ClearAllPools();

            using (var connection = _containerInstance.CreateConnection())
            {
                connection.Open();
                using (var command = new SqlCommand($"ALTER DATABASE [{_databaseName}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE", connection))
                {
                    command.ExecuteNonQuery();
                }
                using (var command = new SqlCommand($"DROP DATABASE [{_databaseName}]", connection))
                {
                    command.ExecuteNonQuery();
                }
            }
        }
 public void Dispose()
 {
     if (!_deleteDatabaseOnDispose)
     {
         return;
     }
     using (var sqlConnection = new SqlConnection(ConnectionString))
     {
         // Fixes: "Cannot drop database because it is currently in use"
         SqlConnection.ClearPool(sqlConnection);
     }
     using (var connection = _containerInstance.CreateConnection())
     {
         connection.Open();
         using (var command = new SqlCommand($"ALTER DATABASE [{_databaseName}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE", connection))
         {
             command.ExecuteNonQuery();
         }
         using (var command = new SqlCommand($"DROP DATABASE [{_databaseName}]", connection))
         {
             command.ExecuteNonQuery();
         }
     }
 }