Azure Data Studio – Database Status Dashboard (5/31)

One of the things I was finding I was missing was when restoring databases and adding into availability groups. It was quite easy to see in SSMS when databases, were synchronized or syncronizing or had just plain, fell over when adding into secondary nodes as sometimes seemed to happen.

It was plain to see in SSMS not so with ADS, the database in the server manage element just didn’t show up if looking at SQL 2008 Secondary using mirroring for example.

Always on secondaries showed up in the database list but not as an Always ON database and it allowed you to click on the database and drill through, not that there was anything to see, it would just say The database X is not accessible, useful. You certainly wouldn’t want to do that for every database!

So a Dashboard was in order to give me some more control. The following steps created the dashboard, there is always more than one way to achieve things as well so I have also explained that as well.

1) Write the SQL that you want to use.  in my case, this is it here below. Using a clever technique that allows me to run against different versions of SQL with different syntax by using EXEC. So if using mirroring it will report the data or if it’s using always on

-- DatabaseStatus.sql #SQL
--Get version so we can run different quiries based on version
DECLARE @SQLServerInstanceVersion INT
SELECT @SQLServerInstanceVersion=


IF @SQLServerInstanceVersion >= 10

WHEN mirroring_state_desc IS NULL THEN ''
ELSE mirroring_state_desc END AS synchronization_state_desc
FROM sys.databases d
INNER JOIN sys.database_mirroring dm ON d.database_id = dm.database_id

EXEC(' SELECT sd.Name,
CASE WHEN sd.is_read_only =1 THEN sd.state_desc + ''(READONLY)'' ELSE sd.state_desc END AS state_desc

, ISNULL(ag.synchronization_state_desc,'''') AS synchronization_state_desc
FROM Master.sys.databases sd
LEFT JOIN master.sys.dm_hadr_database_replica_states ag ON sd.database_id=ag.database_id
WHERE is_local IS NULL or is_local=1
ORDER BY sd.Name'

2) In ADS Ctrl+, to open the setting

3) Type Dashboards (including the s)

4) Click  Dashboards > Server: Properties and Edit in json settings

  1.  Find the dashbaoard.server.widgets section ( as below)

22 Dashboard before

5. After the [ where the red line is paste the following code in. You can edit the code to point to different queries each time. Then go back into ADS and position the dashboard elements how you want and they will be updated.  There is another way of creating the code at the bottom of the blog post.

“name”: “Database Status”,
“gridItemConfig”: {
“sizex”: 2,
“sizey”: 2,
“col”: 3,
“row”: 1
“widget”: {
“insights-widget”: {
“type”: {
“table”: {
“dataDirection”: “horizontal”,
“columnsAsLabels”: true,
“labelFirstColumn”: false,
“legendPosition”: “top”
“queryFile”: “c:\\SQLServerSolutions\\ADS\\DatabaseStatus.sql”

So it looks like the following

22 Dashboard AfterSave it and refresh the dashboard, might need to reopen and you get the following. showing the different status and if its part on and AG or mirroring

23 Dashboard

The alternative method

  1. run the query that you want to create the dashboard for in ADS on the right-hand side are several icons. Choose the one that looks like a bar chart and clickchart
  2.  You can then choose the type of chart you want. In my case, it’s just a table of results I wantChart type
  3. ADS will then open a new window with the following codeand it creates for you the following, you still need to plug it in
This is all on a single line which is a bit annoying, but I am sure there is something that would format it, if your OCD, I had hoped saving would have formatted it but it’s not the case.
This entry was posted in Azure Data Studio, Dashboards, SQLSaturday, Tips & Tricks, TSQL and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s