Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Data Management

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

Authors

Search

XML Feeds

Google Ads

« Instance design; Where to do your work as a DBA and DB DeveloperWhen Books On Line is not really correct »
comments
Rate Post:
submit to reddit Digg!FacebookDotnetkicks

This as many of my blogs, is another DBA task and typically isn't required in a user released reporting situation. I have used it a few times for very specialized reports that the user community runs, so it's possible that you may also be able to use it there. One thing I stress is the use of unsafe assembly in this write and the examples I just put together in order to write the blog for everyone. Security on assemblys might be a good follow up blog.

Two things I'm going to show you today. First is how to scan the network for instances using a SQLCLR UDF. The second is how to use that listing result set in a report so you can quickly run one report like performance monitoring reports for several instances and databases. This basically by making use of dynamic data sources by means of parameters in the connection strings.

This does two major things for you right away.

1) It removes uneccessary clutter in creating folders of identical reports pointing to different data sources.

2) It makes backing these reports up much easier and much easier to maintain changes

So the first taks is scanning the network for SQL Server instances

This can be done with the following SQLCLR UDF.

  1. using System;
  2. using System.Data;
  3. using System.Data.SqlClient;
  4. using System.Data.SqlTypes;
  5. using Microsoft.SqlServer.Server;
  6. using System.Collections;
  7.  
  8. public partial class UserDefinedFunctions
  9. {
  10.     [SqlFunction(FillRowMethodName = "FillRow",TableDefinition = "InstanceName nvarchar(500)", DataAccess=DataAccessKind.Read)]
  11.     public static IEnumerable InstanceFinder()
  12.     {
  13.         System.Data.Sql.SqlDataSourceEnumerator instance = System.Data.Sql.SqlDataSourceEnumerator.Instance;
  14.         System.Data.DataTable dt = instance.GetDataSources();
  15.         return dt.Rows;
  16.     }
  17.  
  18.     public static void FillRow(Object obj, out SqlString InstanceName)
  19.     {
  20.         DataRow r = (DataRow)obj;
  21.         InstanceName = new SqlString(r[0].ToString());
  22.     }
  23.  
  24. };

Create this and deploy it to your DBA restricted database. As most of my readers know that is always a secured database named DBA (go figure!).

Now call the UDF to search the network for SQL Servers.

  1. SELECT * FROM InstanceFinder();

Now to use that in SSRS we have to do a few things. Get a project ready and name it "DBAs Rule". Add a shared data source named DBA. This points to the UDF we're going to use. Next add a blank report named, "SQL DB Check.rdl"

Create a new dataset named "ServerListing" like below

Save that by hitting OK and now let's create a parameter that our dataset will populate. Name the parameter "ServerName". Select "From Query" for available values and find ServerListing in the list. select the only value available for "Value field" and "Label field".

Now back in the Data tab create another dataset. Name this one DBListing. We need a new data source now sense our goal here is to connect to whatever SQL Server the UDF finds. So click the drop down for Data Source and hit create new. Name this DS NoInitialCatalog. That's as meaningful of a name as we can get as that is the key to how we do this. To create this type of connection string all we do is specify the Data Source itself without a initial catalog. For the connection string we need to use our parameter for the server as well. All we do is add it in there as an expression to accomplish that.

like so...

="Data Source=" & Parameters!ServerName.Value

and should appear like this in the prompts...


Save all of this and then in the text for the dataset use

  1. SELECT [Name] FROM sys.databases

This step is import so don't forget to do it. In order for SSRS to know what you are returning from the query on NoIntialCatalog, you need to define it sense validation is out of it's control here and the column will not prefill for you. So in the Fields tab go ahead and enter a field name, "Name" with a type of databases field and value of Name.

Now to actually show this in action we need something on the report so drag a table over and remove the extra columns but the first. Drag over the "Name" from the dataset, "DBListing" and preview the report.

The report is obviously going to be slow loading. You're scanning the network and we all know how annoying hitting that drop down in SSMS and selecting browse network is. To speed this up I actually modified it in most of my DBA related reports. I used my scans that I talk about here and use a simple query over the real-time scan. The scan on load is handy and in a few reports that I do searches I still use it but for speed and security, I use the results from my scan SSIS to run most of them.

So after that runs you should end up with the list, select a instance and hit View Report. After that your database listing should return.

To go farther, you linked the results of the database listing to another parameter like the instance listing. Then run your analysis off of that per database.

About the Author

Ted Krueger has been working in development and database administration for 13+ years. Specialties range from High Availability and Disaster / Recovery setup and testing methods down to custom assembly development for SQL Server Reporting Services. Ted blogs and is also one of the founders of LessThanDot.com technology community. Some of the articles focused on are Backup / Recovery, Security, SSIS and working on SQL Server and using all of the SQL Server features available to create stable and scalable database services. Recent community contributions have been to organize SQL Saturday events in the Chicago-land to Milwaukee-land area for 2010 where he will also be speaking about various SQL Server topics. @onpnt
Social SitingsTwitterLinkedInLTD RSS Feed
2699 views
ssrs
submit to reddit Digg!FacebookDotnetkicks

Comments and Feedback

1 comment

Comment from: thirster42 [Member] Email
****-
cool
27/07/09 @ 07:34

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)