覆盖订阅中的现有文件名

时间:2011-04-08 12:38:34

标签: reporting-services batch-file subscription

我有一个部署.rss文件的批处理文件。 rss文件具有为10个报告创建订阅的脚本。一旦部署了批处理文件,就会触发.rss文件,从而在“报表管理器”中创建订阅(对于所有10个报表)。 我的问题是,每次部署批处理文件时,都会创建一组新的订阅。即,不是覆盖现有订阅,而是创建一组新的重复项。我最终订阅了一份报告。 我需要一个脚本,在部署时覆盖现有文件。我必须使用任何方法吗? 需要帮助..

创建订阅的代码:这非常混乱!忍受我...... :)。

Sub Main()

  rs.Credentials = System.Net.CredentialCache.DefaultCredentials

  'The name of the report for which the DDS are to be created

  Dim fullpath As String = rootpath


  'set extension as Windows File Share

  Dim settings as new ExtensionSettings()
  settings.Extension = "Report Server FileShare"

  'Retrieve rdl files deployed in the server

Dim report As String 
Dim desc As String 
Dim eventType As String = "TimedSubscription"
Dim destpath As String = Path

Dim i as Integer = 0

Dim items As CatalogItem() = rs.ListChildren(fullpath, False)
    For Each item As CatalogItem In items
        If item.Type = ItemTypeEnum.Report Then
    i = i + 1
    desc = item.name                
    report = fullpath &"/" & desc

    Dim drp As DataRetrievalPlan    
Dim ser As Serialization.XmlSerializer = New Serialization.XmlSerializer(GetType(DataRetrievalPlan))
Dim sr As New StringReader("<?xml version=""1.0"" encoding=""utf-16""?>" + Microsoft.VisualBasic.ControlChars.CrLf + "<DataRetrievalPlan xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">" + Microsoft.VisualBasic.ControlChars.CrLf + "  <DataSourceDefinition xmlns=""http://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices"">" + Microsoft.VisualBasic.ControlChars.CrLf + "    <Extension>SQL</Extension>" + Microsoft.VisualBasic.ControlChars.CrLf + "    <ConnectString>Data Source="& DBServer & ";Initial Catalog=ClearviewBilling</ConnectString>" + Microsoft.VisualBasic.ControlChars.CrLf + "    <UseOriginalConnectString>false</UseOriginalConnectString>" + Microsoft.VisualBasic.ControlChars.CrLf + "    <OriginalConnectStringExpressionBased>false</OriginalConnectStringExpressionBased>" + Microsoft.VisualBasic.ControlChars.CrLf + "    <CredentialRetrieval>Store</CredentialRetrieval>" + Microsoft.VisualBasic.ControlChars.CrLf + "    <WindowsCredentials>false</WindowsCredentials>" + Microsoft.VisualBasic.ControlChars.CrLf + "    <ImpersonateUser>false</ImpersonateUser>" + Microsoft.VisualBasic.ControlChars.CrLf + "    <Prompt>Enter a user name and password to access the data source:</Prompt>" + Microsoft.VisualBasic.ControlChars.CrLf + "    <UserName>RptSrvr</UserName>" + Microsoft.VisualBasic.ControlChars.CrLf + "    <Password>deploy1</Password>" + Microsoft.VisualBasic.ControlChars.CrLf + "    <Enabled>true</Enabled>" + Microsoft.VisualBasic.ControlChars.CrLf + "  </DataSourceDefinition>" + Microsoft.VisualBasic.ControlChars.CrLf + "  <DataSet xmlns=""http://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices"">" + Microsoft.VisualBasic.ControlChars.CrLf + "    <Fields>" + Microsoft.VisualBasic.ControlChars.CrLf + "      <Field>" + Microsoft.VisualBasic.ControlChars.CrLf + "        <Alias>ReportID</Alias>" + Microsoft.VisualBasic.ControlChars.CrLf + "        <Name>ReportID</Name>" + Microsoft.VisualBasic.ControlChars.CrLf + "      </Field>" + Microsoft.VisualBasic.ControlChars.CrLf + "      <Field>" + Microsoft.VisualBasic.ControlChars.CrLf + "        <Alias>ReportName</Alias>" + Microsoft.VisualBasic.ControlChars.CrLf + "        <Name>ReportName</Name>" + Microsoft.VisualBasic.ControlChars.CrLf + "      </Field>" + Microsoft.VisualBasic.ControlChars.CrLf + "      <Field>" + Microsoft.VisualBasic.ControlChars.CrLf + "        <Alias>Path</Alias>" + Microsoft.VisualBasic.ControlChars.CrLf + "        <Name>Path</Name>" + Microsoft.VisualBasic.ControlChars.CrLf + "      </Field>" + Microsoft.VisualBasic.ControlChars.CrLf + "    </Fields>" + Microsoft.VisualBasic.ControlChars.CrLf + "    <Query>" + Microsoft.VisualBasic.ControlChars.CrLf + "      <CommandType>Text</CommandType>" + Microsoft.VisualBasic.ControlChars.CrLf + "      <CommandText>exec uspSetSubscriptionParameters "& i & ",'"& destpath &"'</CommandText>" + Microsoft.VisualBasic.ControlChars.CrLf + "      <Timeout>30</Timeout>" + Microsoft.VisualBasic.ControlChars.CrLf + "    </Query>" + Microsoft.VisualBasic.ControlChars.CrLf + "    <CaseSensitivity>False</CaseSensitivity>" + Microsoft.VisualBasic.ControlChars.CrLf + "    <AccentSensitivity>False</AccentSensitivity>" + Microsoft.VisualBasic.ControlChars.CrLf + "    <KanatypeSensitivity>False</KanatypeSensitivity>" + Microsoft.VisualBasic.ControlChars.CrLf + "    <WidthSensitivity>False</WidthSensitivity>" + Microsoft.VisualBasic.ControlChars.CrLf + "  </DataSet>" + Microsoft.VisualBasic.ControlChars.CrLf + "</DataRetrievalPlan>")
drp = ser.Deserialize(sr)

Dim parameters(0) As ParameterValueOrFieldReference

Dim parameter1 As New ParameterFieldReference()
parameter1.ParameterName  = "ReportID"
parameter1.FieldAlias = "ReportID"
parameters(0) = parameter1


Dim extensionParams(6) As ParameterValueOrFieldReference

extensionParams(0) = New ParameterFieldReference()
CType(extensionParams(0),ParameterFieldReference).FieldAlias = "ReportName"
CType(extensionParams(0),ParameterFieldReference).ParameterName = "FILENAME"

extensionParams(1) = New ParameterFieldReference()
CType(extensionParams(1),ParameterFieldReference).FieldAlias = "Path"
CType(extensionParams(1),ParameterFieldReference).ParameterName = "PATH"

extensionParams(2) = New ParameterValue()
CType(extensionParams(2),ParameterValue).Name = "RENDER_FORMAT"
CType(extensionParams(2),ParameterValue).Label = ""
CType(extensionParams(2),ParameterValue).Value = "PDF"

extensionParams(3) = New ParameterValue()
CType(extensionParams(3),ParameterValue).Name = "WRITEMODE"
CType(extensionParams(3),ParameterValue).Label = ""
CType(extensionParams(3),ParameterValue).Value = "OverWrite"

extensionParams(4) = New ParameterValue()
CType(extensionParams(4),ParameterValue).Name = "FILEEXTN"
CType(extensionParams(4),ParameterValue).Label = ""
CType(extensionParams(4),ParameterValue).Value = "True"

extensionParams(5) = New ParameterValue()
CType(extensionParams(5),ParameterValue).Name = "USERNAME"
CType(extensionParams(5),ParameterValue).Label = ""
CType(extensionParams(5),ParameterValue).Value = "SQL_Test"

extensionParams(6) = New ParameterValue()
CType(extensionParams(6),ParameterValue).Name = "PASSWORD"
CType(extensionParams(6),ParameterValue).Label = ""
CType(extensionParams(6),ParameterValue).Value = "Rfgh"


Dim extSettings As New ExtensionSettings()
extSettings.ParameterValues = extensionParams
extSettings.Extension = "Report Server FileShare"


Dim matchData As String = "<ScheduleDefinition xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""><StartDateTime xmlns=""http://schemas.microsoft.com/sqlserver/2006/03/15/reporting/reportingservices"">2011-02-14T01:00:00.000-05:00</StartDateTime></ScheduleDefinition>"
Try
    rs.CreateDataDrivenSubscription(report, extSettings, drp, desc, eventType, matchData, parameters)
    Console.WriteLine("Subscription created successfully for "&desc)

catch ex as System.Exception
    Console.WriteLine(ex)
end try 


        End If

    Next

End Sub

1 个答案:

答案 0 :(得分:1)

可能只是管道错误,使用&gt;&gt;而不是&gt;。一个代码示例会很好。