SQL Server Reporting Service - 一步部署 TFS 项目报表

本文涉及的产品
云数据库 RDS SQL Server,基础系列 2核4GB
RDS SQL Server Serverless,2-4RCU 50GB 3个月
推荐场景:
简介: 上次介绍了 SQL Server Reporting Service 命令行部署报表的基本内容, 利用这些知识我们可以轻松的部署报表, 然而在 TFS 中, 每个项目都有它对应的报表, 这些报表如果要一个个的更新也是件痛苦的事情, 现在我也遇到了这个问题, 针对 TFS 开发了两张报表, 但是如何将...

上次介绍了 SQL Server Reporting Service 命令行部署报表的基本内容, 利用这些知识我们可以轻松的部署报表, 然而在 TFS 中, 每个项目都有它对应的报表, 这些报表如果要一个个的更新也是件痛苦的事情, 现在我也遇到了这个问题, 针对 TFS 开发了两张报表, 但是如何将这些报表应用到所有项目上呢? 结合之前的部署脚本知识, 我们可以使用下面方法实现:

首先建立一个批处理文件ImportWIT.bat, 用来更新某个项目的Work Item定义文件:

 

@ ECHO OFF 

CALL 
" C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat "  x86 

witimport 
/ % 1   / % 2   / f WorkItemDefinitions\Task.xml 
witimport 
/ % 1   / % 2   / f WorkItemDefinitions\Bug.xml 
witimport 
/ % 1   / % 2   / f WorkItemDefinitions\Scenario.xml 

rem 
/ % 1   / % 2  
rem echo Hit any key to 
continue  
rem PAUSE

在WorkItemDefinitions目录下将所有对应Work Item定义文件放入:

image

然后建立一个Reports目录, 将所有需要的报表文件放入, 如下图:

image

然后创建一个脚本文件PublishReports.rss, 内容如下:

 

' ============================================================================= 
'
  File:      PublishSampleReports.rss 
'
 
'
  Summary:  Demonstrates a script that can be used with RS.exe to 
'
         publish the sample reports that ship with Reporting Services. 
'
 
'
--------------------------------------------------------------------- 
'
 This file is part of Microsoft SQL Server Code Samples. 
'
 
'
  Copyright (C) Microsoft Corporation.  All rights reserved. 
'
 
'
 This source code is intended only as a supplement to Microsoft 
'
 Development Tools and/or on-line documentation.  See these other 
'
 materials for detailed information regarding Microsoft code samples. 
'
 
'
 THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
'
 KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 
'
 IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 
'
 PARTICULAR PURPOSE. 
'
============================================================================= 
'
 
'
 1.0 Documentation 
'
 
'
 Read the following in order to familiarize yourself with the sample script. 
'
 
'
 1.1 Overview 
'
 
'
 This sample script uses a script file (.rss) and the script environment to run 
'
 Web service operations on a specified report server. The script creates a folder 
'
 that you specify as a command-prompt variable using the 杤 switch, and then 
'
 publishes the sample reports that ship with Reporting Services to a report server. 
'
 Depending on the location of your sample reports, you may need to modify the 
'
 value of the filePath variable, which references the path to your sample reports. 
'
 
'
 1.2 Script Variables 
'
 
'
 Variables that are passed on the command line with the -v switch: 
'
 
'
 (a) parentFolder - corresponds to the folder that the script creates and uses 
'
     to contain your published reports 
'
 
'
 1.3 Sample Command Lines 
'
 
'
 
'
 1.3.1 Use the script to publish the sample reports to an AdventureWorks Sample Reports folder. 
'
 
'
       rs -i PublishSampleReports.rss -s http://myserver/reportserver 
'
 

Dim  definition  As  [ Byte ]()  =   Nothing  
Dim  warnings  As  Warning()  =   Nothing  
Dim  parentFolder  As   String   =   ""  
Dim  parentPath  As   String   =   " / "   +  parentFolder 
Dim  filePath  As   String   =   " Reports\ "  

img_405b18b4b6584ae338e0f6ecaf736533.gifimg_1c53668bcee393edac0d7b3b3daff1ae.gif
Public   Sub Main() Sub Main() 

    rs.Credentials 
= System.Net.CredentialCache.DefaultCredentials 

    
''Create the parent folder 
    'Try 
    '    rs.CreateFolder(parentFolder, "/", Nothing) 
    '    Console.WriteLine("Parent folder {0} created successfully", parentFolder) 
    'Catch e As Exception 
    '    Console.WriteLine(e.Message) 
    'End Try 

    
''Create the AdventureWorks shared data source 
    'CreateSampleDataSource("AdventureWorks", "SQL", "data source=(local);initial catalog=AdventureWorks") 
    'CreateSampleDataSource("AdventureWorksDW", "OLEDB-MD", _ 
    '    "data source=localhost;initial catalog=Adventure Works DW") 

    
'Publish the sample reports 
    Dim sreader As New System.IO.StreamReader("ProjectInfo.ini"
    
Dim pName As String = "" 
    pName 
= sreader.ReadLine() 

    PublishReport(
"SSW Progress Report", pName) 
    PublishReport(
"SSW Release Plan", pName) 

End Sub
 

img_405b18b4b6584ae338e0f6ecaf736533.gifimg_1c53668bcee393edac0d7b3b3daff1ae.gif
Public   Sub CreateSampleDataSource() Sub CreateSampleDataSource(ByVal name As StringByVal extension As StringByVal connectionString As String
    
'Define the data source definition. 
    Dim definition As New DataSourceDefinition() 
    definition.CredentialRetrieval 
= CredentialRetrievalEnum.Integrated 
    definition.ConnectString 
= connectionString 
    definition.Enabled 
= True 
    definition.EnabledSpecified 
= True 
    definition.Extension 
= extension 
    definition.ImpersonateUser 
= False 
    definition.ImpersonateUserSpecified 
= True 
    
'Use the default prompt string. 
    definition.Prompt = Nothing 
    definition.WindowsCredentials 
= False 

    
Try 
        rs.CreateDataSource(name, parentPath, 
False, definition, Nothing
        Console.WriteLine(
"Data source {0} created successfully", name) 

    
Catch e As Exception 
        Console.WriteLine(e.Message) 
    
End Try 

End Sub
 

img_405b18b4b6584ae338e0f6ecaf736533.gifimg_1c53668bcee393edac0d7b3b3daff1ae.gif
Public   Sub PublishReport() Sub PublishReport(ByVal reportName As StringByVal projectName As String
    
Try 
        
Dim stream As FileStream = File.OpenRead(filePath + reportName + ".rdl"
        definition 
= New [Byte](stream.Length) {} 
        stream.Read(definition, 
0CInt(stream.Length)) 
        stream.Close() 

    
Catch e As IOException 
        Console.WriteLine(e.Message) 
    
End Try 

    
Try 

        parentPath 
= "/" + projectName 

        warnings 
= rs.CreateReport(reportName, parentPath, False, definition, Nothing

        
If Not (warnings Is NothingThen 
            
Dim warning As Warning 
            
For Each warning In warnings 
                Console.WriteLine(warning.Message) 
            
Next warning 

        
Else 
            Console.WriteLine(
"Report: {0} published successfully with no warnings", reportName) 
        
End If 

    
Catch e As Exception 
        Console.WriteLine(e.Message) 
    
End Try 
End Sub


根据上面的代码可以看到需要一个保存项目名的文件, 最后我们就创建一个ProjectInfo.ini文件, 该文件内容留空即可.

上述文件都船舰好了之后接着创建一个总体的脚本, 命名为Update.bat, 内容为:

@ ECHO OFF 

copy nul ProjectInfo.ini 
/
echo 
% 2 >> ProjectInfo.ini 

RS 
- " PublishReports.rss "   - " http://%1/ReportServer/ "  
ImportWIT.bat 
% 1   % 2

 

以上就是所有需要创建的内容, 如下:

image

其中RS.EXE文件可以在SQL Server安装目录中找到.

接下来我们来执行升级某个Team Project的具体操作:

打开CMD, 输入如下命令:

update.bat [TFSServerName] [TeamProjectName]

 

这样就可以将一个Team Project中的工作项和报表更新成脚本中提到的内容.

完整升级包下载: http://files.cnblogs.com/WilsonWu/TFS_2008_SSWTemplateUpdateScript_ver1-1.zip

相关实践学习
使用SQL语句管理索引
本次实验主要介绍如何在RDS-SQLServer数据库中,使用SQL语句管理索引。
SQL Server on Linux入门教程
SQL Server数据库一直只提供Windows下的版本。2016年微软宣布推出可运行在Linux系统下的SQL Server数据库,该版本目前还是早期预览版本。本课程主要介绍SQLServer On Linux的基本知识。 相关的阿里云产品:云数据库RDS SQL Server版 RDS SQL Server不仅拥有高可用架构和任意时间点的数据恢复功能,强力支撑各种企业应用,同时也包含了微软的License费用,减少额外支出。 了解产品详情: https://www.aliyun.com/product/rds/sqlserver
目录
相关文章
|
5月前
|
关系型数据库 MySQL 网络安全
5-10Can't connect to MySQL server on 'sh-cynosl-grp-fcs50xoa.sql.tencentcdb.com' (110)")
5-10Can't connect to MySQL server on 'sh-cynosl-grp-fcs50xoa.sql.tencentcdb.com' (110)")
|
7月前
|
SQL 存储 监控
SQL Server的并行实施如何优化?
【7月更文挑战第23天】SQL Server的并行实施如何优化?
189 13
|
7月前
|
SQL
解锁 SQL Server 2022的时间序列数据功能
【7月更文挑战第14天】要解锁SQL Server 2022的时间序列数据功能,可使用`generate_series`函数生成整数序列,例如:`SELECT value FROM generate_series(1, 10)。此外,`date_bucket`函数能按指定间隔(如周)对日期时间值分组,这些工具结合窗口函数和其他时间日期函数,能高效处理和分析时间序列数据。更多信息请参考官方文档和技术资料。
114 9
|
7月前
|
SQL 存储 网络安全
关系数据库SQLserver 安装 SQL Server
【7月更文挑战第26天】
97 6
|
7月前
|
存储 SQL C++
对比 SQL Server中的VARCHAR(max) 与VARCHAR(n) 数据类型
【7月更文挑战7天】SQL Server 中的 VARCHAR(max) vs VARCHAR(n): - VARCHAR(n) 存储最多 n 个字符(1-8000),适合短文本。 - VARCHAR(max) 可存储约 21 亿个字符,适合大量文本。 - VARCHAR(n) 在处理小数据时性能更好,空间固定。 - VARCHAR(max) 对于大文本更合适,但可能影响性能。 - 选择取决于数据长度预期和业务需求。
605 1
|
7月前
|
SQL Oracle 关系型数据库
MySQL、SQL Server和Oracle数据库安装部署教程
数据库的安装部署教程因不同的数据库管理系统(DBMS)而异,以下将以MySQL、SQL Server和Oracle为例,分别概述其安装部署的基本步骤。请注意,由于软件版本和操作系统的不同,具体步骤可能会有所变化。
596 3
|
6月前
|
SQL 安全 Java
驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“The server selected protocol version TLS10 is not accepted by client
驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“The server selected protocol version TLS10 is not accepted by client
611 0
|
7月前
|
SQL 存储 安全
数据库数据恢复—SQL Server数据库出现逻辑错误的数据恢复案例
SQL Server数据库数据恢复环境: 某品牌服务器存储中有两组raid5磁盘阵列。操作系统层面跑着SQL Server数据库,SQL Server数据库存放在D盘分区中。 SQL Server数据库故障: 存放SQL Server数据库的D盘分区容量不足,管理员在E盘中生成了一个.ndf的文件并且将数据库路径指向E盘继续使用。数据库继续运行一段时间后出现故障并报错,连接失效,SqlServer数据库无法附加查询。管理员多次尝试恢复数据库数据但是没有成功。
|
6月前
|
SQL 运维 Oracle
SQL Server 项目中 SQL 脚本更新、升级方式,防止多次重复执行
SQL Server 项目中 SQL 脚本更新、升级方式,防止多次重复执行
105 0
|
7月前
|
SQL 存储 关系型数据库
关系型数据库SQL Server学习
【7月更文挑战第4天】
109 2

热门文章

最新文章