使用 ReportClientDocument.Open() 方法繫結至 Unmanaged RAS 伺服器
附註 |
---|
本頁說明的是在 Crystal Reports for Visual Studio 中沒有提供,但在升級版本中提供的功能。如需關於 Crystal Reports for Visual Studio 的詳細資訊,請參閱「何謂 Crystal Reports for Visual Studio?」。如需關於升級版本的詳細資訊,請參閱「升級選項」。 |
物件模型
這個報表繫結案例使用 ReportClientDocument (請參閱 「與 ReportClientDocument 物件模型 (RAS) 繫結的報表」)。
報表位置
報表位於 Unmanaged RAS (請參閱 「報表應用程式伺服器 (RAS)」) 伺服器有存取權限的檔案目錄中。
說明
這個報表繫結案例會直接存取 ReportClientDocument 物件模型。它會將檔案目錄路徑 (當成物件) 及整數 0 (Visual Basic 中的選擇性參數) 傳遞至 Open() 方法,而這個方法屬於 ReportClientDocument。如需程式碼範例,請參閱下面一節。
優點
- 回溯相容性:提供能與 ReportClientDocument 物件模型 (使用 RAS 9 (含) 以上版本) 中的報表進行互動的可行方法。
- 最佳化效能:因報表應用程式伺服器 (RAS) 報表引擎的卓越效能而產生顯著的效能增益。請參閱「比較所有 Business Objects 報表解決方案之間的架構」。
- 便利的可攜性:維護所有會與 ReportDocument 物件模型報表互動的原始程式碼,而且仍能提供對基礎 ReportClientDocument 物件模型的完整存取,只需透過 ReportDocument.ReportClientDocument 屬性。
附註 ReportClientDocument 物件模型允許您以程式碼方式建立或修改,並將變更儲存至報表定義檔案。如需詳細資訊,請參閱<架構>中的「ReportClientDocument 物件模型 (RAS)」。
- 直接的程式碼編寫:允許直接存取 ReportClientDocument 物件模型。
缺點
- 效能潛力有限:升級至 Unmanaged RAS 伺服器可大幅增加報表效能,但程度不如升級至 Managed RAS 伺服器來得大。
使用 ReportClientDocument 的 Open 方法,從本機檔案目錄將報表載入至 RAS 伺服器
- 安裝 Unmanaged RAS 伺服器 9 或以上版本,並確認其正在運作。
這個程序只能與「專案設定」一節中建立的專案搭配使用。「專案設定」包含特定命名空間參考以及本程序所需的程式碼組態;您必須具備這個組態,否則將無法完成此程序。因此,在您開始本程序前,必須先遵循「專案設定」中的步驟進行。
RAS 伺服器只適用於 Web 專案。
- 在 ConfigureCrystalReports() 方法 (「專案設定」 中所建立) 內,加入包含本機報表路徑的字串宣告。
<table>
<colgroup>
<col style="width: 100%" />
</colgroup>
<thead>
<tr class="header">
<th><img src="images\36bhtx7w.alert_note(zh-tw,VS.90).gif" alt="Note" class="note" />附註</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><p>這個路徑是儲存 RAS 報表的預設目錄。RAS 伺服器可能會以「拒絕存取」錯誤來拒絕其他報表路徑。</p></td>
</tr>
</tbody>
</table>
``` vb
Dim reportPath As String = "C:\Program Files\Crystal Decisions\" _ & "Report Application Server 10\Reports\" _ & "World Sales Report.rpt"
```
``` csharp
string reportPath = "C:\\Program Files\\Crystal Decisions" + "\\Report Application Server 10\\Reports" + "\\World Sales Report.rpt";
```
- 將 reportPath 字串轉換為 Object 變數。
<table>
<colgroup>
<col style="width: 100%" />
</colgroup>
<thead>
<tr class="header">
<th><img src="images\36bhtx7w.alert_note(zh-tw,VS.90).gif" alt="Note" class="note" />附註</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><p>Open() 方法 (屬於 ReportClientDocument) 需要物件型別的字串,而非字串型別的字串。</p></td>
</tr>
</tbody>
</table>
``` vb
Dim reportPathAsObject As Object = CType(reportPath, Object)
```
``` csharp
object reportPathAsObject = (object)reportPath;
```
宣告並產生 ReportClientDocument 執行個體。
Dim myReportClientDocument As ReportClientDocument = New ReportClientDocumentClass()
ReportClientDocument reportClientDocument = new ReportClientDocumentClass();
同時將報表路徑 (當作物件變數) 以及當作整數 0 (在 visual Basic 中是選擇性) 的 Options 參數傳遞給 Open 方法 (屬於 ReportClientDocument 執行個體)。
<table>
<colgroup>
<col style="width: 100%" />
</colgroup>
<thead>
<tr class="header">
<th><img src="images\36bhtx7w.alert_note(zh-tw,VS.90).gif" alt="Note" class="note" />附註</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><p>這樣會開啟本機檔案目錄中的報表,並將其載入 Unmanaged Report Application Server (RAS)。</p></td>
</tr>
</tbody>
</table>
``` vb
myReportClientDocument.Open(reportPathAsObject, 0)
```
``` csharp
reportClientDocument.Open(ref reportPathAsObject, 0);
```
將 ReportClientDocument 執行個體繫結至 CrystalReportViewer 控制項。
myCrystalReportViewer.ReportSource = myReportClientDocument
crystalReportViewer.ReportSource = reportClientDocument;
若要檢視報表,請建置並執行專案。