Can the Solar System have a close encounter with a star, and how likely is it? Is it possible that this kind of close encounter has happened during the lifetime of the Solar System?
This question is still very much studied in astrophysics! The answer depends on how "close" you want your close encounter to be. It is very unlikely that a passing star entered the "core" of our system, within 1000 astronomical units (au, that is 1000 times the distance Sun-Earth), otherwise it would have had dramatic consequences on the planets' stability. The distance at closest approach of the typical close encounter is more likely to be more than 100,000 au, which will have no significant effect on most of the Solar System bodies. The stellar neighborhood in which our Solar System currently is is not very dense, and we have a very good knowledge on our closest neighbors thanks to the satellite Gaia, so we are pretty sure there will not be a very close encounter in the next million of years.
However, the Sun is thought to have formed in a star cluster like most stars did. So in the first million of years of the Solar System's life, before the cluster dissipates, the chances to have had a close encounter were much bigger. In fact, a close encounter at around 1000 au is one possible explanation for how Planet 9 (if it exists) could have got its current large orbit!