从VB.Net部署SSRS RDL文件 - 共享数据源问题

时间:2016-03-31 13:19:07

标签: vb.net web-services reporting-services datasource ssrs-2008-r2

我目前正在开发一个实用程序来帮助自动执行报表部署过程。多个文件夹,多个文件夹,多个服务器。

我正在使用reportservice2010.asmx网络服务,我正在将我的文件部署到服务器 - 所以大部分都在那里。

我的问题是我有共享数据集和共享数据源,它们部署到单个文件夹,与报告文件夹分开。部署发生时,Web服务在本地查找数据源而不是数据源文件夹,从而产生如下错误:

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.

已部署数据源/集并且报告功能正常但我需要抑制这些错误消息,因为它们可能隐藏了其他实际错误。

我可以硬编码一个查询,检查数据源/集是否存在,并通过它手动过滤它们,但它似乎非常低效。有什么方法可以告诉Web服务在哪里查找这些文件或其他人使用的其他方法?

我没有考虑更改报告,因此从

读取数据源
/DataSources/DataSourceName 

因为有很多报告,而且我们现有项目的配置方式并非如此。

非常感谢提前。

1 个答案:

答案 0 :(得分:1)

我意识到你正在使用VB,但是如果你使用网络上的一个翻译器将它从C#转换为VB,这可能会给你一个线索。

希望这会让你在正确的方向上领先。

当特定文件夹中的所有报告(此处称为“父文件夹”)都使用相同的共享数据源时,我使用此命令将所有报告设置为相同的共享数据源(在这种情况下" / 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());
}

}

要打电话给我,我在“主要&#39;方法:

 GetListOfObjectsInGivenFolder_and_ResetTheReportDataSource("0_Contacts");

在这种情况下&#34; 0_Contacts&#34;是父文件夹,它本身位于根目录中,其中包含我要将其DataSource重置为新的Shared DataSource的所有报告。然后该方法调用另一种方法&#34; ResetTheDataSource_for_a_Report&#34;它实际上为报告设置了DataSource。

相关问题