2013-04-03 71 views
2

編輯SSRS 2012部署的DataSet參考:我想我可以簡化這個問題有點要求是需要只知道什麼:更新數據源,並從C#

我與C#中使用的SSRS 2010網站工作服務: 'ReportService2010.asmx'http://technet.microsoft.com/en-us/library/ee640743.aspx

我可以使用方法'CreateDataSource'在SSRS服務器http://(servername)/ ReportServer的實例上創建數據源。

我還可以使用方法'CreateCatalogItem'在服務器上創建一個引用項目的RDL本地文件的報告,將其序列化爲一個字節數組,然後將其作爲'Definition'傳遞給在其上創建它的方法服務器。

現在我所做的一切與一個警告,以及一個主要的作品。我只能將所有內容部署到同一個文件夾。如果我部署數據源來說'數據源'文件夾,然後報告說:'測試報告',報告不知道它有一個共享的數據源來引用不同的位置。因此,我在technet文章中挖了一點點,並試圖'GetItemDataSources'方法,但它只給出了ReportingService2010.DataSource返回類型的名稱和類型。 有誰知道鏈接了一個「報告」或數據源「數據集的的CatalogItem財產「的方法,所以當部署指向在SSRS服務器上的不同文件夾中的參考?必須有辦法做到這一點,因爲我知道我可以從商業智能開發工作室進行部署,並且可以執行此操作。

回答

2

我已經部署報告文件時,類似的問題;當通過rs.exe或代碼進行部署時,會遇到報告失去與數據源鏈接的問題。

我們通過我們的應用程序部署後立即解決了這個由明確指向服務器端的數據源的報告;這是類似於你想要做什麼?

總之,這裏的稍微適應代碼我們在報告中部署應用程序中使用:

static void SetReportDataSource(string reportPath) 
    { 
     string dsPath = CombinePath(DataSourcePath, DataSourceFolder, DataSourceName); 

     DataSourceReference dsRef = new DataSourceReference() 
     { 
     Reference = dsPath 
     }; 
     DataSource ds = new DataSource(); 
     ds.Item = dsRef as DataSourceDefinitionOrReference; 
     ds.Name = DataSourceName; 


     var rptDataSources = Server.GetItemDataSources(reportPath); 
     foreach (var rptDs in rptDataSources) 
     { 
     Server.SetItemDataSources(filePath, new DataSource[] { ds }); 
     } 
    } 

所以,基本上我們有這樣定義數據源名稱,數據源位置上的服務器信息變量,同樣報告。他們可以在不同的文件夾中。

在此基礎上,我們創建了一個新的參照數據源,然後重新指向使用SetItemDataSources這個報告。

此整理出數據源的問題對我來說,反正。不確定共享數據集以及它們如何處理所有這些,但希望這會有所幫助。

此外,只是認爲這將使用ReportService2005端點,但ReportService2010可能不會太不同。

編輯:

對於這裏提到的路徑,這些是相對於服務器,例如/Reports/。在定義包含目標的ReportService2010對象的Url屬性時,不需要全限定名稱。

+0

是的,這似乎正是我需要的,但我沒有找到「CombinePath」您在聲明Web服務的實例後擁有的方法。這是你使用的本地方法嗎?我很好奇當你設置定義路徑時,你只需要/(文件夾)/(對象)還是你需要http://(servername)/ ReportServer /(文件夾)/(對象)?這看起來像我想查看你的代碼,讓我測試它,看看我能否爲它工作。 – djangojazz 2013-04-04 15:58:23

+0

我已經添加了一些關於路徑的更多信息。對不起,'CombinePath'只是一個在其他地方定義的私有方法;應該對複製和粘貼更加小心。不幸的是,我現在無法運行代碼來查看需要清理的內容,但希望它仍然足以讓您走上正確的軌道。 – 2013-04-04 16:44:43

+0

謝謝我必須改變你的代碼部分,但它的工作原理,我不能聲明一個新的DataSource []並讓它工作出於某種原因,奇怪。但是這個方法很有效,所以我給你答案。如果您發現數據源的「名稱」不必與服務器上的rds文件的「實際名稱」相匹配,我對您的編碼感到好奇。 EG:如果某人懶惰,它會將其稱爲「DataSource1」,但可能會引用「Data Sources/TestSource」。看來GetItemDataSources的方法給你的名字,但不是參考。有任何想法嗎? – djangojazz 2013-04-04 18:26:13

0

也許這可能是一些幫助。我用它來重新設置數據源在給定的父文件夾的所有報告,它的子文件夾:

using System; 
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()); 
    } 
} 

}