Browse DevX
Sign up for e-mail newsletters from DevX


Automating Smart-Client Report Deployments : Page 2

Building reports is often easier than getting them into users' hands and making sure they're used correctly, but now you can use the SQL Server Reporting Services Web service to automate deployment and control execution of reports.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Web Services Sample 1—Report Installer
When creating a setup, you'll want to add code to install your reports automatically. The sample code deploys reports using a Windows Forms user interface for simplicity's sake, but for real applications, you will probably want to automate your server installation using a Visual Studio Setup project and the techniques described in the article "Building Custom Installer Classes in .NET" in combination with the code outlined in this article.

Figure 2. The Report Installer Sample: The first sample application gathers the information required to deploy a smart-client report.
The sample displays a form that gets user input, and then calls three methods of the example Deployer class (see Figure 2).

The CreateFolder Method
The sample CreateFolder method creates a folder on your reporting server, checking to make sure it does not already exist. If it does exist, the method returns without doing anything. The ReportServerFolder argument is the user-defined name of the folder that will hold reports and data sources. You can use any valid folder name as specified by the Reporting Services documentation. Note that a valid folder name cannot include the following reserved characters: ? ; @ & = : + $ , \ * > < | . " .

The first step is to check for an existing folder with the same name by creating a SearchCondition object to specify the search criteria to use with the FindItems method. Search conditions are quite simple; they contain a property name, and the value you want to match. You can search for any standard property name visible on-screen in the report manager—in this case, Name or Description.

srcFolderCond = New ReportServer.SearchCondition With srcFolderCond .Condition = ConditionEnum.Equals .Name = "Name" .Value = ReportServerFolder End With srchResults = mobjReportServer.FindItems _ ("/", BooleanOperatorEnum.And, _ New ReportServer.SearchCondition() {srcFolderCond})

The FindItems method requires a starting path (use a slash (/) to start from the root), an operator to indicate how to combine the search conditions, and an array of search conditions. Note that the FindItems method expects an array of SearchCondition objects—you can pass multiple SearchCondition objects within the array to create more complex queries. FindItems returns an array of CatalogItem objects.

To ensure that the search matches an existing folder rather than some other reporting services object type with the same name, the code loops through the returned CatalogItem array to check if one of the returned CatalogItem objects is a Folder.

' Check that found item(s) is a folder For Each srchResult In srchResults If srchResult.Type = ItemTypeEnum.Folder Then blnExists = True End If Next

After determining that the folder does not already exist, you can create the folder using the CreateFolder method:

mobjReportServer.CreateFolder(ReportServerFolder, "/", CreateStandardProperties)

The CreateFolder Web method takes three arguments: The name of the folder to create, the path for the new folder (which must start with the "/" character) and an array of user-defined properties. You can pass Nothing (or null in C#) for this argument if you don't have any user-defined properties to add. The example adds an "Application" property by passing in the array of ReportServer.Property objects returned from a custom CreateStandardProperties function.

Private Function CreateStandardProperties() _ As ReportServer.Property() Dim objProperty As New ReportServer.Property Dim objProperties() As ReportServer.Property = _ {objProperty} objProperty.Name = "Application" objProperty.Value = _ "DevX Reporting Services WebService Sample" Return objProperties End Function

If you place your application-specific reports and data sources in a folder, you will help users to understand that the reports belong to your application (and that they should leave them alone!).

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date