Azure SQL Database - Changing Between Database Using Variable

The Azure SQL Server allows accessing multiple SQL databases via the same instance, however it does not allow switching between the databases as they are separate physical instances (I guess).

When creating an MS SQL data source within Grafana, it currently asks for a database which you are running queries against.

What I would like to do would be to fill in the parametre effectively using a dashboard variable.

For example, the dashboard would do something like the following to get a list of databases populated in the dropdown list:

SELECT name FROM master.dbo.sysdatabases

This part works because we’re on the master database by default.

From here, I would then like to run queries against the specific database. Currently because the plugin source specifies the database at the plugin source level, I don’t think this is possible.

Would anyone happen to have any suggestions? Thinking currently might have to mirror the data into another database somewhere.

Hi
You can try to create 1 datasource each for one database, if there are only a few databases. Say ds-db1,ds-db2 etc.

Then in dashboard variable you can create a datasource variable name as dsdyn with value as db-$dbname.
dbname is the variable with the list of database names using your query.
Then in your panel you choose datasource as dbdyn.

So when you change dbname, dbdyn also changes

I did consider doing this, though there are around 400 databases and sadly may not be the easiest solution.

It looks like there’s a data_source API however so perhaps doing this could be an option.