设为首页 收藏本站
查看: 1187|回复: 0

[经验分享] SQL Server Reporting Service

[复制链接]

尚未签到

发表于 2015-6-28 17:57:58 | 显示全部楼层 |阅读模式
  上次介绍了 SQL Server Reporting Service 命令行部署报表的基本内容, 利用这些知识我们可以轻松的部署报表, 然而在 TFS 中, 每个项目都有它对应的报表, 这些报表如果要一个个的更新也是件痛苦的事情, 现在我也遇到了这个问题, 针对 TFS 开发了两张报表, 但是如何将这些报表应用到所有项目上呢? 结合之前的部署脚本知识, 我们可以使用下面方法实现:
  首先建立一个批处理文件ImportWIT.bat, 用来更新某个项目的Work Item定义文件:
  

DSC0000.gif @ECHO OFF

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

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

rem /t %1 /p %2
rem echo Hit any key to continue DSC0001.gif
rem PAUSE

  在WorkItemDefinitions目录下将所有对应Work Item定义文件放入:
DSC0002.png
  然后建立一个Reports目录, 将所有需要的报表文件放入, 如下图:
DSC0003.png
  然后创建一个脚本文件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\"

DSC0004.gif DSC0005.gif Public Sub Main()Sub Main()
DSC0006.gif
    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)

DSC0007.gif End Sub

Public Sub CreateSampleDataSource()Sub CreateSampleDataSource(ByVal name As String, ByVal extension As String, ByVal 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

Public Sub PublishReport()Sub PublishReport(ByVal reportName As String, ByVal projectName As String)
    Try
        Dim stream As FileStream = File.OpenRead(filePath + reportName + ".rdl")
        definition = New [Byte](stream.Length) {}
        stream.Read(definition, 0, CInt(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 Nothing) Then
            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 /y
echo %2>>ProjectInfo.ini

RS -i "PublishReports.rss" -s "http://%1/ReportServer/"
ImportWIT.bat %1 %2
  
  以上就是所有需要创建的内容, 如下:
DSC0008.png
  其中RS.EXE文件可以在SQL Server安装目录中找到.
  接下来我们来执行升级某个Team Project的具体操作:
  打开CMD, 输入如下命令:

update.bat [TFSServerName] [TeamProjectName]  
  这样就可以将一个Team Project中的工作项和报表更新成脚本中提到的内容.
  完整升级包下载: http://files.iyunv.com/WilsonWu/TFS_2008_SSWTemplateUpdateScript_ver1-1.zip

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-81287-1-1.html 上篇帖子: Sql server2012连接Sql server 2008时出现的问题:已成功与服务器建立连接,但在登陆过程中发生错误。(provider:SSL Prov 下篇帖子: 《Microsoft Sql server 2008 Internals》读书笔记--第十一章DBCC Internals(11)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表