Change record status: 
Project: 
Introduced in branch: 
9.1.x
Introduced in version: 
9.1.0
Description: 

New public method Drupal\views\Plugin\views\query\Sql::getConnection() has been created. This method return the correct database connection for the current view. The correct database connection for a view does not have to be the default database connection. It can also be to an external database or to a replica database.

How to use:

/** @var \Drupal\views\ViewExecutable $view */
$view = \Drupal\views\Views::getView('your_view');
$view->setDisplay();
/** @var \Drupal\Core\Database\Connection $connection */
$connection = $view->getQuery()->getConnection();
Impacts: 
Module developers