Currently Browsing: SQL Server Reporting Services

Mapping with Virtual Earth in SQL Server Reporting Services

After seeing an excellent article by Wayne Berry about Mapping in SQL Server Reporting Services using the Google Maps API, I was inspired to see what I could do with Virtual Earth.

The answer: not much.

Virtual Earth does has a stellar SDK. The SDK is all JavaScript based, so it may not be used by SQL Server Reporting Services. Virtual Earth does not have a static mapping API. However, there are unsupported ways to get a single image tile–I used this virtual earth example application (veTile) as a basis for retrieving the tile URL.

I translated the code from C# to VB.NET so I could use it directly in reporting services. The code allows you to provide a latitude, longitude, and a zoom level and get back the closest virtual earth tile. The problem is that the resolution is only as good as a single map tile. The actual location of the latitude and longitude could be anywhere on the tile.

Virtual Earth mapping example

Virtual Earth mapping example

The good news, like the Google maps example, is that you can use the tiles in SSRS because no JavaScript is required. If you find a way to improve the resolution, let me know.

The SSRS source code of the report: Virtual Earth Mapping Example source code (vemappingexample.rdl)

In case you just want to get the map tile URL in Visual Basic, I am providing the Virtual Earth Helper source code (VB.NET code). The class (VEHelper) has a single public static method (GetVETileUrl).

Easy multi-value parameters in SQL Server Reporting Services

I recently came across an application where I needed to use a multi-value parameter in SQL Server Reporting Services (SSRS).  I always seemed to have trouble with these in the past.  This time I found them very easy to use because I found (re-discovered?) a simple way.

The basic idea is to set up a parameter as if it were going to be a single value parameter with the topmost row selected by default.  I will walk through the steps of this scenario.

I chose the AdventureWorks database to do this sample and focused on June 2004 Sales to get an easy dataset to work with.

1. Create the basic dataset:

Sales By Territory Dataset

2. Set up the layout for the report:

3. Preview the report with no parameters:

4. Create a new dataset for the territories list:

5. Set up the parameter, TerritoryID, like a normal single-value parameter.  Be sure to set the default value to make it default to the topmost row in the list.  In this case, the topmost is “Australia”, TerritoryID of 9.

6a. Apply the filter to the table.  Notice that I am not editing the dataset, but simply adding a filter to the table properties.  If you are usually the type to edit the dataset (like myself), just hang with me for a second.  Right-click the edge of the table and then choose Properties:

6b.  Modify the table properties to add the filter.  Since you can’t read it all, it says

=Fields!TerritoryID.Value = Parameters!TerritoryID.Value

7. Check the finished result.  We now have a report with a single parameter.  The topmost selection, Australia, is automatically selected and our filter is applied by default.

8. So far, so good–there is nothing extraordinary about what we’ve done so far.  Now, we simple make the parameter multi-value by changing the report parameters and checking the Multi-value box:

9. Don’t rush off just yet, or you’ll see this error message when you choose Preview:

An error occurred during local report processing.
An error has occurred during report processing.
The processing of FilterExpression for the table ‘Sales’ cannot be performed. Cannot compare data of types System.Byte and System.Object[].  Please check the data type returned by the Filter Expression.

10.  You need to make one small change to the filter.  Open the table properties again, but this time change the operator from equals (=) to IN.  Since the Parameters!TerritoryID.Value now contains a comma separated list, we need to search IN instead of comparing.

11. Now, preview your report.  The left image shows the initial preview, the right image shows the drop-down list blown out, you can see that Select All is selected by default.

One caveat is that performance is not going to be top notch because Reporting Services is filtering on the entire dataset every time.  It would (most likely, depending on your implementation) be faster to filter in the dataset.  However, this approach often requires a lot of development work on the T-SQL side to get it working.  This approach is easy and quick enough for many applications.  Enjoy.

Update: I found a good example of the hard way to do multi-value parameters (by using SQL).  If you scroll down to the second post, there is source code there for converting a delimited string into a table variable.  I have re-formatted the charlist_to_table source code to make it more legible.

CAML queries, SSRS, and datetime fields

I’ve been using Enesys Software’s product RS Data Extension to query data out of SharePoint 2007 lists in SQL Server (2005) Reporting Services.  One quirk with the queries is that they use CAML and the dates must be in a particular format, ISO8601.

I wanted users to use the standard date-picker, but there is no way to format the date inside the query.  My work-around is a classic Reporting Services pattern – create an internal parameter that does the formatting for you.  The format string for VBScript is “yyyy-MM-ddTHH:mm:ss”.

Below is a screenshot of the Report Parameters dialog. I used the following code to just grab today’s date (no time).

     =CDate(CDate(Now()).ToString("MM/dd/yyyy"))

For the second parameter, I create an internal parameter that is dependent on the first.  This will prevent it from showing on the report and it will not be filled in until the start date is chosen.  Default value:

     =CDate(Parameters!StartDate.Value).ToString("yyyy-MM-ddTHH:mm:ss")

I created a test report to show how this works.  Here is the report definition:

Below is the report preview:  You can now use the parameter in your CAML query.

One other note on CAML date fields.  The time is ignored by default.  If you want to include the time, you must specify another attribute.  Example:

<Geq>
<FieldRef Name="LastModified" />
<Value Type="DateTime" IncludeTimeValue="TRUE">@LastModified!</Value>
</Geq>

I found a helpful post on CAML & DateTime that might be useful for you too.

SharePoint “User not found” error with Reporting Services in integrated mode

I encountered an error the other day while trying to get a SharePoint 2007 (WSS 3.0) site running with SQL Server Reporting Services 2005 in integrated mode.  While trying to access any report .RDL files inside a document library, I got the “User not found” error from SharePoint.  After looking in the logs, I could not find anything.  What I did note, was that the development site worked, but the production site did not.

One difference between them – the names of the Application Pool that SharePoint was running under.  In development it was just “spsite” but in production it was “www.spsite.com”.

I renamed the application pool and *poof*, the site began to work.  I don’t understand the mechanism, but just thought I’d post in case someone else out there encounters it.

UPDATE: I’ve blogged about another reason why you might get the “User not found” error and possible solutions.

Page 2 of 212