ReportServer Tutorial

This Document is a walk trough of how to set up a Report Server For newbies

SoftWare Environment

SQLServer Express 2014

  1. Link.

  2. When you install the SQLServer 2014, make sure if report server is checked. it is checked defaultly.

  3. Open Reporting Services Configuration Manager just like SQLServer Manager Studio. There are two URLs needed to be noted.
    that is WebServiceURL and ReportManagerURL. The second one is used to manager you report template. The first One is used to generating the
    report for client like winform ReportViewer.

  4. By Default, we need to open IE with runAsAdministrator feature to access to the manager website. if we hope to bypass this limit, we can follow this link to assign the necessary privilege.


Manager Report Server with PowerShell

  1. instance a object of ReportServer
$ReportUrl = "http://xxx/ReportServer/ReportService2010.asmx?wsdl"
$rs = New-WebServiceProxy -Uri $reportUrl -UseDefaultCredential -Namespace "SSRS"
  1. Now we can rock over it by using this guide

  2. refer link here

Code Snap:

param(
    [Parameter(Mandatory=$false)]
    [string]$ReportServerUrL = "http://xxx:xxx/ReportServer/ReportService2010.asmx?wsdl",
   # [string]$ReportServerUrL = "http://localhost/ReportServer/ReportService2010.asmx?wsdl",

    [Parameter(Mandatory=$false)]
    [string]$LocalRDLFilePath = "xxx\Reports\SSRSReports",

    [Parameter(Mandatory=$false)]
    [string]$ReportFolderPath = "/AgencyNoticeReports",

    [Parameter(Mandatory=$false)]
    [string]$SharedDataSourcePath = "/AgencyNoticeReports/Agency"
)
Function Get-ReportServerInstance
 {
     param(

     [Parameter(Mandatory=$true)]
     [string]$ReportUrl,

     [Parameter(Mandatory=$false)]
     [string]$Namespace
     )
 
     return New-WebServiceProxy -Uri $ReportUrl -UseDefaultCredential -Namespace $Namespace
 }

 Function Delete-ItemsByPath
 {
     param(
         [Parameter(Mandatory=$true)]
         [object]$RS,

         [Parameter(Mandatory=$true)]
         [string]$Path,

         [Parameter(Mandatory=$false)]
         [bool]$IsRecurse=$false
     )
     $RS.DeleteItem($Path)
     if($IsRecurse){$RS.ListChildren($Path,$IsRecurse) | %{$RS.DeleteItem($_.Path)}}
 }

 Function Upload-ReportToRemoteServer
 {
     param(
         [Parameter(Mandatory=$true)]
         [object]$RS,

         [Parameter(Mandatory=$true)]
         [string]$RDLFilePath,

         [Parameter(Mandatory=$true)]
         [string]$ReportServerPath
     )
     Resolve-Path -Path $RDLFilePath
     $RDLFile = Get-Item -Path $RDLFilePath
     $reportName = [System.IO.Path]::GetFileNameWithoutExtension($RDLFile.Name)
     $bytes = [System.IO.File]::ReadAllBytes($RDLFile.FullName)
     $warnings=$null
     $report = $rs.CreateCatalogItem(
        "Report",         # Catalog item type
        $reportName,      # Report name
        $ReportServerPath,# Destination folder
        $true,            # Overwrite report if it exists?
        $bytes,           # .rdl file contents
        $null,            # Properties to set.
        [ref]$warnings)   # Warnings that occured while uploading.
    $warnings | %{  Write-Output ("Warning: {0}" -f $_.Message)}
 }

 Function Create-ReportFolder
 {
     Param(
         [Parameter(Mandatory=$true)]
         [object]$RS,

         [Parameter(Mandatory=$true)]
         [string]$FolderName,

         [Parameter(Mandatory=$false)]
         [string]$ParentFolderPath="/"
     )
     $RS.CreateFolder($FolderName,$ParentFolderPath,$null)
 }

 Function Test-ItemByPath
 {
     Param(
         [Parameter(Mandatory=$true)]
         [object]$RS,

         [Parameter(Mandatory=$true)]
         [string]$Path
     )
     Return ($Rs.ListChildren("/",$true) | ?{$_.Path -eq $Path}) -ne $null
 }

 Function Update-DataSource
 {
     Param(
         [Parameter(Mandatory=$true)]
         [object]$RS,

         [Parameter(Mandatory=$true)]
         [string]$SharedDataSourcePath,

         [Parameter(Mandatory=$true)]
         [string]$ReportFolderPath
     )
     $RS.ListChildren($ReportFolderPath,$false) |?{$_.TypeName -eq "Report"} | %{
           $referencedDataSourceName = (@($rs.GetItemReferences($_.Path, "DataSource")))[0].Name
            # Change the datasource for the report to $SharedDataSourcePath
            # Note that we can access the types such as DataSource with the prefix 
            # "SSRS" only because we specified that as our namespace when we 
            # created the proxy with New-WebServiceProxy.
            $dataSource = New-Object SSRS.DataSource
            $dataSource.Name = $referencedDataSourceName      
            # Name as used when designing the Report
            $dataSource.Item = New-Object SSRS.DataSourceReference
            $dataSource.Item.Reference = $SharedDataSourcePath # Path to the shared data source as it is deployed here.
            $rs.SetItemDataSources($_.Path, [SSRS.DataSource[]]$dataSource)
    }
 }


$Rs = Get-ReportServerInstance -ReportUrl $ReportServerUrL  -Namespace "SSRS"
if((Test-ItemByPath -RS $RS -Path $ReportFolderPath) -eq $false)
{
    Create-ReportFolder -RS $RS -FolderName $ReportFolderPath.remove(0,1)
}
Resolve-Path $LocalRDLFilePath
Get-ChildItem -Path $LocalRDLFilePath | ?{$_.Name -like "*.rdl"} | %{Upload-ReportToRemoteServer -RS $RS -RDLFilePath $_.FullName -ReportServerPath $ReportFolderPath }
Update-DataSource -RS $RS -SharedDataSourcePath $SharedDataSourcePath -ReportFolderPath $ReportFolderPath



posted @   kongshu  阅读(216)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示