• PublishReport.rss


    Dim parentFolder As String = "Test"
    Dim connectString as String = "data source=.;initial catalog=Test" 'Connect String
    Dim DataSourceName = "DataSource1"
    Dim userName as String = "sa"  '登录数据库的账户
    Dim password as String = "pass@word1"
    Dim definition As [Byte]() = Nothing
    Dim warnings As Warning() = Nothing
    Dim parentPath As String = "/" + parentFolder
    Dim filePath As String= "D:\Test\Report\Report\" 'the folder contains the rdl files
    Public Sub Main()
    Dim fileArr() As String
    Dim file As String
    Dim i As Integer
    rs.Credentials = _
    System.Net.CredentialCache.DefaultCredentials
    CreatParentFolder()
    CreateDataSource()
    fileArr = System.IO.Directory.GetFiles(filePath)
    For i = 0 To fileArr.Length - 1
    file = fileArr(i)
    file = file.Replace(System.IO.Directory.GetCurrentDirectory() + "\", "")
    If file.Substring(file.Length - 3) = "rsd" Then
    file = file.Substring(0, file.Length - 4)
    PublishDataSet(file)
    ElseIf file.Substring(file.Length - 3) = "rdl" Then
    file = file.Substring(0, file.Length - 4)
    PublishReport(file)

    CreateItemHistorySnapshot(parentPath+"/"+file)  '创建快照
    End If
    Next i
    End Sub
    Public Sub CreatParentFolder()
    'Create the parent folder
    Try
    rs.CreateFolder(parentFolder, "/", Nothing)
    Console.WriteLine("Parent folder created: {0}", parentFolder)
    Catch soapEx As System.Web.Services.Protocols.SoapException
    If soapEx.Detail("ErrorCode").InnerXml = "rsItemAlreadyExists" Then
    Console.WriteLine("Folder {0} already exists.", parentFolder)
    ElseIf soapEx.Detail("ErrorCode").InnerXml = "rsItemLengthExceeded" Then
    Console.WriteLine("Folder name cannot exceed 260 characters.", parentFolder)
    Else
    Console.WriteLine(soapEx.Detail("ErrorCode").InnerXml)
    End If
    Catch e As Exception
    Console.WriteLine(e.Message)
    End Try
    End Sub
    Public Sub CreateDataSource()
    Dim parent As String = "/" + parentFolder

    'Define the data source definition.
    Dim definition As New DataSourceDefinition()
    definition.CredentialRetrieval = CredentialRetrievalEnum.Integrated '如果是远程部署要设置成Store
    definition.UserName = userName
    definition.Password = password
    definition.ConnectString = connectString
    definition.Enabled = True
    definition.EnabledSpecified = True
    definition.Extension = "SQL"
    definition.ImpersonateUser = False
    definition.ImpersonateUserSpecified = True
    definition.UseOriginalConnectString=False

    'Use the default prompt string.
    definition.Prompt = Nothing
    definition.WindowsCredentials = False

    Try
    rs.CreateDataSource(DataSourceName, parent, True, definition, Nothing) 'overwrite data source
    Console.WriteLine("DataSource: {0} published successfully with no warnings", DataSourceName)
    Catch soapEx As System.Web.Services.Protocols.SoapException
    If soapEx.Detail("ErrorCode").InnerXml = "rsItemAlreadyExists" Then
    Console.WriteLine("DataSource {0} already exists.", DataSourceName)
    Else
    Console.WriteLine(soapEx.Detail("ErrorCode").InnerXml)
    End If
    Catch e As Exception
    Console.WriteLine(e.Message)
    End Try

    End Sub
    Public Sub PublishReport(ByVal reportName As String)
    Dim reportPath As String
    reportPath = filePath + reportName+".rdl"
    Try
    Dim stream As FileStream = File.OpenRead(reportPath)
    definition = New [Byte](stream.Length - 1) {}
    stream.Read(definition, 0, CInt(stream.Length))
    stream.Close()

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

    Try
    Dim parentPath As String = "/" + parentFolder
    rs.CreateCatalogItem("Report", reportName, parentPath, True, _
    definition, Nothing, warnings)

    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} created " + _
    "successfully with no warnings", reportName)
    End If

    Catch e As SoapException
    Console.WriteLine(e.Detail.InnerXml.ToString())
    End Try

    End Sub
    Public Sub PublishDataSet(ByVal reportName As String)
    Dim reportPath As String
    reportPath = filePath + reportName+".rsd"
    Try
    Dim stream As FileStream = File.OpenRead(reportPath)
    definition = New [Byte](stream.Length - 1) {}
    stream.Read(definition, 0, CInt(stream.Length))
    stream.Close()

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

    Try
    Dim parentPath As String = "/" + parentFolder
    rs.CreateCatalogItem("DataSet", reportName, parentPath, True, _
    definition, Nothing, warnings)

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

    Else
    Console.WriteLine("DataSet: {0} created " + _
    "successfully with no warnings", reportName)
    End If

    Catch e As SoapException
    Console.WriteLine(e.Detail.InnerXml.ToString())
    End Try

    End Sub
    Public Sub PublishDataSource(ByVal reportName As String)
    Dim reportPath As String
    reportPath = filePath + reportName+".rds"
    Try
    Dim stream As FileStream = File.OpenRead(reportPath)
    definition = New [Byte](stream.Length - 1) {}
    stream.Read(definition, 0, CInt(stream.Length))
    stream.Close()

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

    Try
    Dim parentPath As String = "/" + parentFolder
    rs.CreateCatalogItem("DataSource", reportName, parentPath, True, _
    definition, Nothing, warnings)

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

    Else
    Console.WriteLine("DataSource: {0} created " + _
    "successfully with no warnings", reportName)
    End If

    Catch e As SoapException
    Console.WriteLine(e.Detail.InnerXml.ToString())
    End Try

    End Sub

    public Sub CreateItemHistorySnapshot(ItemPath)
    Dim definition As New ScheduleDefinition()
    Dim returnValue As String
    definition.StartDateTime = _
    New DateTime(2003, 3, 1, 14, 0, 0)
    Dim recurrence As New WeeklyRecurrence()
    Dim days As New DaysOfWeekSelector()
    days.Monday = True
    days.Tuesday = True
    days.Wednesday = True
    days.Thursday = True
    days.Friday = True
    days.Saturday = False
    days.Sunday = False
    recurrence.DaysOfWeek = days
    recurrence.WeeksInterval = 1
    recurrence.WeeksIntervalSpecified = True
    definition.Item = recurrence
    Try
    rs.SetItemHistoryOptions(ItemPath,true, true,definition)
    returnValue=rs.CreateItemHistorySnapshot(ItemPath,warnings)
    If Not (warnings Is Nothing) Then
    Dim warning As Warning
    For Each warning In warnings
    Console.WriteLine(warning.Message)
    Next warning
    Else
    Console.WriteLine("Snapshot: {0} created " + _
    "successfully with no warnings",returnValue )
    End If
    Catch e As SoapException
    Console.WriteLine(e.Detail.InnerXml.ToString())
    End Try
    End Sub

    public sub CreateSchedule() '创建共享快照计划
    {
    Dim definition As New ScheduleDefinition()
    Dim scheduleID As String = ""

    ' Create the schedule definition.
    definition.StartDateTime = _
    New DateTime(2003, 3, 1, 14, 0, 0)
    Dim recurrence As New WeeklyRecurrence()a
    Dim days As New DaysOfWeekSelector()
    days.Monday = True
    days.Tuesday = True
    days.Wednesday = True
    days.Thursday = True
    days.Friday = True
    days.Saturday = False
    days.Sunday = False
    recurrence.DaysOfWeek = days
    recurrence.WeeksInterval = 1
    recurrence.WeeksIntervalSpecified = True
    definition.Item = recurrence

    Try
    Dim site As String = "http://<Server Name>"

    scheduleID = rs.CreateSchedule("My Schedule", _
    definition, site)
    Console.WriteLine("Schedule created with ID {0}", _
    scheduleID)

    Catch e As SoapException
    Console.WriteLine(e.Detail.InnerXml.ToString())
    End Try
    }
    End Sub

    PublishReports.bat

    rs -i PublishReports.rss -s http://localhost/reportserver -e Mgmt2010 -u sa -p pass@word1

    参考 :http://technet.microsoft.com/zh-cn/library/ee640743.aspx reportservice2010类

    http://technet.microsoft.com/zh-cn/library/ee640242(v=sql.105)

  • 相关阅读:
    从解放劳动力来看未来的科技进程
    流程变换与抽象
    EntityFramework Any 生成的sql语句超长。
    值类型引用类型List Remove 方法Remove不掉哪一个项。
    CentOS 7.0编译安装Nginx1.6.0+MySQL5.6.19+PHP5.5.14
    SVN的安装配置(linux)
    【题解】洛谷 P1979 [NOIP2013 提高组] 华容道 | 20211119 模拟赛 Y【BFS 最短路】
    【题解】[Codechef CALLSCHE] Call Center Schedule | 20211127 模拟赛 或负(fortune)【网络流】
    【题解】[Codeforces 1086F] Forest Fires | 20211119 模拟赛 o【插值 扫描线】
    NOIP2021 SC 迷惑行为小赏
  • 原文地址:https://www.cnblogs.com/GreenGrass/p/2777741.html
Copyright © 2020-2023  润新知