Deploying SSRS RDL files from VB.Net - Issue with shared datasources

谁说我不能喝 提交于 2019-12-12 03:34:52

问题


I am currently developing a utility to help automate our report deployment process. Multiple files, in multiple folders, to multiple servers.

I am using the reportservice2010.asmx web service, and I am deploying my files to the server - so most of the way there.

My issue is that I have shared data sets and shared data sources, which are deployed to individual folders, separate to the report folders. When the deployment occurs the web service looks locally for the data source rather than in the data source folder, giving an error like:

The dataset ‘CostReduction’ refers to the shared data source ‘CostReduction’, which is not
published on the report server.  The shared data source ‘CostReduction’ must be published
before this report can run.

The data source/set has been deployed and the report functions correctly but I need to suppress these error messages as they may be hiding other actual errors.

I can hard code a lookup that checks if the data source/set exists and manually filter them via that, but it seems very in-efficient. Is there any way I can tell the web service where to look for these files or another approach that other people have used?

I'm not looking at changing the reports so the data source is read from

/DataSources/DataSourceName 

as there are lots of reports and that's not how our existing projects are configured.

Many thanks in advance.


回答1:


I realize you are using VB, but perhaps this will give you a clue if you convert it from C# to VB, using one of the translators on the web.

Hopefully this will give you a lead in the right direction.

When All the reports in a particular folder, referred to here as the 'parent folder', all use the same Shared Data source, I use this to set all the reports to the same shared Data Source (in this case "/DataSources/Shared_New")

using GetPropertiesSample.ReportService2010;
using System.Diagnostics;
using System.Collections.Generic;   //<== required for LISTS
using System.Reflection;

namespace GetPropertiesSample
{
class Program
{
static void Main(string[] args)
{
    GetListOfObjectsInGivenFolder_and_ResetTheReportDataSource("0_Contacts");  //<=== This is the parent folder
}

private static void GetListOfObjectsInGivenFolder_and_ResetTheReportDataSource(string sParentFolder)
{
    // Create a Web service proxy object and set credentials
    ReportingService2010 rs = new ReportingService2010();
    rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

    CatalogItem[] reportList = rs.ListChildren(@"/" + sParentFolder, true);

    int iCounter = 0;

    foreach (CatalogItem item in reportList)
    {
        iCounter += 1;
        Debug.Print(iCounter.ToString() + "]#########################################");

        if (item.TypeName == "Report")
        {
            Debug.Print("Report: " + item.Name);
            ResetTheDataSource_for_a_Report(item.Path, "/DataSources/Shared_New");   //<=== This is the DataSource that I want them to use
        }
    }
}

private static void ResetTheDataSource_for_a_Report(string sPathAndFileNameOfTheReport, string sPathAndFileNameForDataSource)
{
    //from: http://stackoverflow.com/questions/13144604/ssrs-reportingservice2010-change-embedded-datasource-to-shared-datasource

    ReportingService2010 rs = new ReportingService2010();
    rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

    string reportPathAndName = sPathAndFileNameOfTheReport;
    //example of sPathAndFileNameOfTheReport  "/0_Contacts/207_Practices_County_CareManager_Role_ContactInfo";

    List<ReportService2010.ItemReference> itemRefs = new List<ReportService2010.ItemReference>();
    ReportService2010.DataSource[] itemDataSources = rs.GetItemDataSources(reportPathAndName);

    foreach (ReportService2010.DataSource itemDataSource in itemDataSources)
    {
        ReportService2010.ItemReference itemRef = new ReportService2010.ItemReference();
        itemRef.Name = itemDataSource.Name;

        //example of DataSource i.e. 'itemRef.Reference':    "/DataSources/SharedDataSource_DB2_CRM";
        itemRef.Reference = sPathAndFileNameForDataSource;

        itemRefs.Add(itemRef);
    }

    rs.SetItemReferences(reportPathAndName, itemRefs.ToArray());
}

}

To Call it I use this in the 'Main' Method:

 GetListOfObjectsInGivenFolder_and_ResetTheReportDataSource("0_Contacts");

In this case "0_Contacts" is the parent folder, itself located in the root directory, that contains all the reports for which I want to reset their DataSources to the new Shared DataSource. Then that Method calls the other method "ResetTheDataSource_for_a_Report" which actually sets the DataSource for the report.



来源:https://stackoverflow.com/questions/36334676/deploying-ssrs-rdl-files-from-vb-net-issue-with-shared-datasources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!