How to connect/Update datasource onLoading the dashboard

I am using grafana version 8.2.1

I am trying to connect to or update a datasource on dashboard load
Explanation: Say, I have created a grafana dashboard using a datasource X which is postgres. Now I have many databases in postgres. Say my postgresDB have 3 databases, X1, X2, X3.
I have created one dashboard and one datasource and connected the datasource to the dashboard. Now I will pass some informations while the dashboard loads and then with that information, the datasource connection should be changed from X1 or X2 or X3 ( database name,username and pasword should be updated for that datasource). Once the correct database is connected, then grafana should execute the dashboard query from that particular database and fetch data

Is this procedure achievable in any possible ways? Suggestion are welcome.

THANKS.

you can try using datasource variables

For that I need to connect to multiple datasources right, But in the mentioned scenario I will connect to only one datasource and should alter the datasource on the fly

How does grafana pulls data from databases. Is the connection is always in ready state or is the connection to the database only made when the dashboard loads?

How will you send some info while dashboard loads?