I have been building dashboard using Reporting Services (SSRS) for a client of mine. The dashboard is going to be used to display useful information on their SQL Server instance, the information contained in the reports will be retrieved from DMVs. Information like the SQL Server wait types, information on a SQL Server instance, along with other useful information such as page life expectancy (PLE) buffer cache hit ratio, Expensive IO queries and the like. This can be useful when performance tuning and monitoring SQL Server. How I went about creating this report will follow in future posts but in order to get this information ‘real time’ from several different SQL Servers required me to build a dynamic data source.
In this post we will look at how we build this dynamic connection.
First up we need to create a database to hold information on the servers we want to connect to. There is likely to be a nice easy way of getting this information for you automatically using something like PowerShell but for the purposes of this post we will collect the data manually.
Create a database and a table to hold the SQL Server information:
/*create a database to house the server and instance information
--this can be any data source you like
--in my case it's SQL Server database*/
CREATE DATABASE [ServerList]
/*Create a simple table to store the SQL Server information*/
CREATE TABLE [dbo].[ServerList](
[Severname] [varchar](50) NULL
) ON [PRIMARY]
/*Populate the table with some server names*/
INSERT INTO [ServerList].[dbo].[ServerList]
Create new Report Server Project
We have our list of servers that we want to connect too stored nicely in a database table, next we will create a Report Server Project and create new report. Our report will show wait times for each server instance, the query for the report is courtesy of Glenn Berry’s (Blog | @GlennAlanBerry) Diagnostic queries. So we’ll create a new project
Once we have a new project we need create a new report, right click the reports folder in the “Solution Explorer” and select <New Report> this starts up the Report Wizard:
Create a data source to an instance of your choice, we will change this later to connect to a server from a drop-down list.
Click next and plug in Glenn’s waits query:
Complete the report wizard and we should have report that connects to our server and displays information on what SQL Server is waiting on.
Create a Data Set for the server list
Next we need to create a data set that connects to our list of servers
We have a data set based on our server list data source. Next up we want to plug this dataset into a parameter
Create a Parameter
Right-Click on the <Parameters> folder and select <Add Parameter> call it ServerName
Select <Available Values> and select <Get Values from a query>
The final thing for us to do is pass our parameter into our waits data source so we connect to the correct server as selected by the report viewer. To do this we need to change our waits data source to pass the parameter in as the server name. The code looks similar to this:
="Data Source=" & Parameters!ServerName.Value
We plug this code into the expression on the waits data source
When we preview our report, we will need to first select a server from our drop down list, and select <View Report> we will then get the waits information from the sever chosen.