覆盖订阅中的现有文件名

发布于 2024-10-31 01:55:29 字数 7682 浏览 4 评论 0原文

我有一个部署 .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

I have a batch file that deploys a .rss file. The rss file has script that creates a subscription for 10 reports. Once when the batch file is deployed, the .rss file is triggered which in turn cretaes subscription in the "report manager"(For all the 10 reports).
My problem is, each time I deploy the batch file a new set of subscription is created. i.e) instead of overwriting the existing subscription, a new set of duplicates are created. i end up with many subscriptions for a single report.
I need a script that overwrites the existing files on deploying.Do I have to use any method??
Help needed..

code to create subscription:This is pretty messy!bear with me..:)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掩耳倾听 2024-11-07 01:55:29

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

Probably it's just a piping error, using >> instead of >. A code example would be nice.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文