C# ReportingServices SetReportDataSources异常操作您正在尝试项错误

C# ReportingServices SetReportDataSources异常操作您正在尝试项错误,c#,reporting-services,C#,Reporting Services,我只是想设置一个共享数据源。 我一直有例外 此项目类型不允许您尝试对项目执行的操作 也许我的周围有些东西混在一起,但我无法确定 filepath=/Base/Vendor(报告的完整路径) datasource=IBBase public static void UpdateDataSource(string filepath, string datasource) { ReportingService rs = new ReportingService();

我只是想设置一个共享数据源。 我一直有例外

此项目类型不允许您尝试对项目执行的操作

也许我的周围有些东西混在一起,但我无法确定

filepath=/Base/Vendor(报告的完整路径)
datasource=IBBase

 public static void UpdateDataSource(string filepath, string datasource)
    {
        ReportingService rs = new ReportingService();
        rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

        ServicesReport.DataSourceReference reference = new ServicesReport.DataSourceReference();
        reference.Reference = filepath;
        ServicesReport.DataSource[] dataSources = new ServicesReport.DataSource[1];
        ServicesReport.DataSource ds = new ServicesReport.DataSource();
        ds.Item = (ServicesReport.DataSourceDefinitionOrReference)reference;
        ds.Name = datasource;
        dataSources[0] = ds;

        try
        {
            rs.SetReportDataSources(filepath, dataSources);
            Console.WriteLine("New reference set for the report.");

        }

        catch (SoapException e) 
        {
            Console.WriteLine(e.Detail.InnerXml.ToString());
        }
    }

此连接调用使用SetItemDataSources方法报告相同的错误代码:

微软给出的答案的底线是,数据源名称不能是任意的。它必须与当前报告关联的现有报告相匹配。您是否可以检查报表服务器上的报表配置引用的数据源与您在代码中尝试连接的数据源完全相同


如果没有,您已经找到了问题的可能原因。

这非常有帮助。这是对我有用的东西

//************ Associate the shared datasource to the report ************

//Step 1 - Get the datasource for the report
DataSource[] _currReportDataSource = 
_ssrsService.GetItemDataSources(report.Path);

//Step 2 - Create a reference to the shared datasource for the tenent
SSRS_Service.DataSourceReference _dsRef = new DataSourceReference();
_dsRef.Reference = <Path to the datasource>     //Usually like "/Folder Name/Datasource Name"

//Step 3 - Create a new datasource object with reference to the shared     datasource for the tenent
DataSource _newReportDataSource = new DataSource();
_newReportDataSource.Item = _dsRef;     //this line sets the reference of the object to the shared datasource
_newReportDataSource.Name = _currReportDataSource[0].Name;      //we will use the current name of the report as it is exists now.  Defaultly named as "DataSource1"

//Step 4 - Load the datasource object (with reference to shared datasource) to a temp array as the SetItemDataSources method requires an array.
DataSource[] dsArray = new DataSource[1];
dsArray[0] = _newReportDataSource;

_ssrsService.SetItemDataSources(report.Path, dsArray);      //Set the datasource for the report to the shared datasource
//**********将共享数据源与报表关联************
//步骤1-获取报告的数据源
数据源[]\u currReportDataSource=
_ssrsService.GetItemDataSources(report.Path);
//步骤2-为tenent创建对共享数据源的引用
SSRS_Service.DataSourceReference_dsRef=新的DataSourceReference();
_dsRef.Reference=//通常类似于“/文件夹名称/数据源名称”
//步骤3-参照tenent的共享数据源创建一个新的数据源对象
DataSource _newReportDataSource=新数据源();
_newReportDataSource.Item=\u dsRef//此行设置对象对共享数据源的引用
_newReportDataSource.Name=\u currReportDataSource[0]。名称//我们将使用报告的当前名称,因为它现在已经存在。默认命名为“数据源1”
//步骤4-将datasource对象(参照共享数据源)加载到临时数组中,因为SetItemDataSources方法需要数组。
DataSource[]dsArray=新数据源[1];
dsArray[0]=\u newReportDataSource;
_ssrsService.SetItemDataSources(report.Path,dsArray)//将报表的数据源设置为共享数据源