- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们正在本地开发一些报告。这些报告将安装在客户的计算机上。但我们无法在线访问这台机器。
到目前为止我已经做到了:
文件夹包含:
此脚本将在 ReportServer 中创建所有需要的文件夹,加载数据源,然后加载数据集,最后加载报告。 这有效,我可以打开门户并可以看到我的对象。
下载的 rdl 文件将其数据集引用设置为普通数据集的名称 - 为什么...我花了几个小时才发现,引用必须包含数据集的完整(内部)路径...现在分页报告真的可以工作了,heureka!
这不适用于
如何通过 PowerShell 上传移动报告?
如何上传自定义品牌包?
有更好的方法吗?我对 PowerShell 相当陌生,因此愿意接受任何建议! TIA
删除了脚本片段,因为我自己发布了一个全面的答案......
在我自己的答案的底部有一些悬而未决的问题...我很乐意将赏金给予某人,但它似乎丢失了...无论如何:如果 Anybode 可以回答至少部分剩余的悬而未决的问题问题很有可能获得 150 分:-)
最佳答案
微软决定让我们这些可怜的技术人员独自处理这个......
似乎没有人能够提供帮助 - 即使有赏金! - 我将陈述到目前为止我发现的内容:
以下 PowerShellScript 是在断开连接的计算机上运行的独立部署。
$DeployDirectory=".\MyProduct Reports\"
$DbURL="1.2.3.4"
$srvURI="http://1.2.3.4/ReportServer"
$srvURL="http://1.2.3.4/reports"
#Write RS Report folders
$rootDir="/MyProduct Reports"
#导入模块并创建文件夹。这也可能是自动化的(在光盘上找到的目录结构之外,但这取决于您......)
Import-Module .\ReportingServicesTools
New-RsFolder -ReportServerUri $srvURI -Path "/" -Name "MyProduct Reports"
New-RsFolder -ReportServerUri $srvURI -Path $rootDir -Name "MyProduct Data"
New-RsFolder -ReportServerUri $srvURI -Path $rootDir -Name "EventLog"
New-RsFolder -ReportServerUri $srvURI -Path $rootDir -Name "Public Reports"
New-RsFolder -ReportServerUri $srvURI -Path $rootDir -Name "Report Audit"
Write-Host "RS Report folders written"
#创建共享数据源
New-RsDataSource -RsFolder ($rootDir + "/MyProduct Data") -Name "MyProduct_DatabaseConnection" -Extension "SQL" -ConnectionString ("Data Source=" + $DbURL + ";Integrated Security=True;Initial Catalog=master;") -CredentialRetrieval "Integrated"
Write-Host "Shared data source created"
#修改共享数据集文件:必须更改对服务器 URL 的硬编码引用
$allRSDs = Get-ChildItem -Recurse -Path $DeployDirectory | Where-Object -FilterScript {$_.Extension -eq ".rsd"}
Write-Host "RSDs fetched"
$xml = New-Object System.Xml.XmlDocument
$nsMngr = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
$nsMngr.AddNamespace("rd","http://schemas.microsoft.com/SQLServer/reporting/reportdesigner")
$allRSDs | % {
$FileName=$_.FullName;
$xml.Load($FileName);
$xml.SelectNodes("//rd:ReportServerUrl",$nsMngr) |
% {$_.InnerText=$srvURI};
$newContent = $xml.InnerXml;
Set-Content -Path $FileName -Value $newContent
}
Write-Host "Shared data set files modified"
Write-RsFolderContent -Recurse -ReportServerUri $srvURI -Path ($DeployDirectory + "MyProduct Data") -RsFolder ($rootDir + "/MyProduct Data")
Write-Host "Shared DataSets created"
#将所有创建的共享数据集从数据库中读取到表变量中
$con = New-Object System.Data.SqlClient.SqlConnection
$con.ConnectionString=("Data Source=" + $DbURL + ";Integrated Security=True;Initial Catalog=master;")
$con.Open();
Write-Host "connection opened"
$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.Connection = $con
Write-Host "command created"
$cmd.CommandText = "SELECT ItemID, [name] AS DataSetName, [Path] AS DataSetPath, LEN([name]) AS SortOrder `
FROM ReportServer.dbo.[Catalog]`
WHERE [Type]=8"
$adapt = New-Object System.Data.SqlClient.SqlDataAdapter
$adapt.SelectCommand = $cmd
$ds = New-Object System.Data.DataSet
$adapt.Fill($ds)
$allDs = New-Object System.Data.DataTable
$allDs = $ds.Tables[0]
Write-Host "shared datasets fetched into cache"
Class shDs {[string]$ItemId=""; [string]$DataSetName=""; [string]$DataSetPath="";}
function Get-SharedDataSet([string]$DataSetName){
$retVal = New-Object shDs
$Search = ("'" + $DataSetName + "' LIKE DataSetName + '%'")
$Sort = ("SortOrder DESC")
$dsRow = $allDs.Select($Search,$Sort)[0]
$retVal.ItemID=$dsRow["ItemID"].ToString().Trim()
$retVal.DataSetPath=$dsRow["DataSetPath"].ToString().Trim()
$retVal.DataSetName=$dsRow["DataSetName"].ToString().Trim()
return $retVal
}
Write-Host "function to fetch referenced shared dataset created"
$con.Close()
Write-Host "connection closed"
#修改分页报告文件:新写入的共享数据集必须写入report-XML
$allRDLs = (Get-ChildItem -Recurse -Path $DeployDirectory |
Where-Object -FilterScript {$_.Extension -eq ".rdl"})
$xml = New-Object System.Xml.XmlDocument
$nsMngr = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
$nsMngr.AddNamespace("rd","http://schemas.microsoft.com/SQLServer/reporting/reportdesigner")
$nsMngr.AddNamespace("ns","http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition")
$allRDLs | % {
$FileName=$_.FullName;
$xml.Load($FileName);
$xml.SelectNodes("//rd:ReportServerUrl",$nsMngr) |
% {$_.InnerText=$srvURI};
$xml.SelectNodes("//ns:SharedDataSetReference",$nsMngr) |
% {
$it = ("/" + $_.Innertext);
$ref=$it.SubString($it.LastIndexOf("/")+1);
$ds = Get-SharedDataSet($ref);
$_.InnerText=$ds.DataSetPath
Write-Host ("DataSetPath: " + $_.InnerText)
};
$newContent = $xml.InnerXml;
Set-Content -Path $FileName -Value $newContent
}
Write-Host "paginated report files modified"
Write-RsFolderContent -Recurse -ReportServerUri $srvURI -Path ($DeployDirectory + "EventLog") -RsFolder ($rootDir + "/EventLog")
Write-RsFolderContent -Recurse -ReportServerUri $srvURI -Path ($DeployDirectory + "Public Reports") -RsFolder ($rootDir + "/Public Reports")
Write-RsFolderContent -Recurse -ReportServerUri $srvURI -Path ($DeployDirectory + "Report Audit") -RsFolder ($rootDir + "/Report Audit")
Write-Host "paginated reports created"
#修改移动报告文件:这更复杂......文件实际上是 ZIP。这些 ZIP 包含多个文件。 metadata.xml
和 sources.xml
包含硬编码引用,必须更改
$allMobs = (Get-ChildItem -Recurse -Path $DeployDirectory |
Where-Object -FilterScript {$_.Extension -eq ".rsmobile"})
#Unzip SomeName.rsmobile into SomeName.rsmobile.Unzipped
Add-Type -AssemblyName System.IO.Compression.FileSystem
Add-Type -AssemblyName System.Collections
$unzippedList = New-Object System.Collections.ArrayList
Class zippedMobs {[string]$DirectoryName; [string]$rsMobileName; [string]$FileName;}
Get-ChildItem -Recurse $path |
Where-Object -FilterScript {$_.Extension -eq ".rsmobile"} |
% {
$zm = New-Object zippedMobs;
$zm.DirectoryName = ($_.FullName + ".Unzipped");
$zm.rsMobileName=$_.FullName;
$zm.FileName=$_.Name;
$unzippedList.Add($zm);
[System.IO.Compression.ZipFile]::ExtractToDirectory($zm.rsMobileName,$zm.DirectoryName)
}
Write-Host "Mobile Reports: Files unzipped"
#打开所有解压文件夹中的所有metadata.xml文件并修改
$xml = New-Object System.Xml.XmlDocument
$nsMngr = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
$nsMngr.AddNamespace("ns","http://schemas.microsoft.com/sqlserver/reporting/2016/02/mobilereportpackage")
$nsMngr.AddNamespace("mrp","http://schemas.microsoft.com/sqlserver/reporting/2016/02/mobilereportpublisher")
$unzippedList | % {
$FileName=($_.DirectoryName + "\metadata.xml");
$xml.Load($FileName);
$xml.SelectNodes("//ns:dataSet",$nsMngr) |
% {
$ref=$_.Attributes["name"].Value;
$ds = Get-SharedDataSet($ref);
$_.Attributes["mrp:Server"].Value=$srvURL;
$_["id"].InnerText=$ds.ItemID;
$_["path"].InnerText=$ds.DataSetPath
};
$newContent = $xml.InnerXml;
Set-Content -Path $FileName -Value $newContent
}
Write-Host "Mobile Reports: All metadata.xml re-mapped"
#打开所有解压文件夹中的所有sources.xml文件并修改
$xml = New-Object System.Xml.XmlDocument
$unzippedList | % {
$FileName=($_.DirectoryName + "\sources.xml");
$xml.Load($FileName);
$xml.SelectNodes("//Shared") |
% {
$ref=$_.Attributes["Name"].Value;
$ds = Get-SharedDataSet($ref);
$_.Attributes["ServerUri"].Value=$srvURL;
$_.Attributes["Guid"].Value=$ds.ItemID;
$_.Attributes["DataItemLocation"].Value=$ds.DataSetPath
};
$newContent = $xml.InnerXml;
Set-Content -Path $FileName -Value $newContent
}
Write-Host "Mobile Reports: All sources.xml re-mapped"
#重命名所有原始 .rsmobile 文件
$unzippedList | % {Rename-Item -Path $_.rsMobileName -NewName ($_.FileName + ".old")}
Write-Host "Mobile Reports: Renamed all orginal .rsmobile files"
#Create new ZIP file for all mobile reports
$unzippedList | % {
[System.IO.Compression.ZipFile]::CreateFromDirectory($_.DirectoryName,$_.rsMobileName,[System.IO.Compression.CompressionLevel]::NoCompression, $FALSE)
}
Write-Host "Re-created all mobile report files"
尽管创建的 ZIP 文件(新的 .rsmobile
文件)有效且包含正确的内容,但无法通过 SSRS 门户上传它们(错误:报告包无效)。但是——够有趣的了! - 当您使用资源管理器的发送到压缩目录
并相应地重命名生成的ZIP文件时,可以上传该文件。
.rsmobile
(ZIP 文件)? (必须与 Windows 在发送到压缩文件夹时隐式压缩的方式相同)关于sql-server - 使用 PowerShell 在客户计算机上部署 SSRS 报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47579949/
我是一名优秀的程序员,十分优秀!