Overwriting existing filename in subscription
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.VisualBasi开发者_如何学运维c.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
Probably it's just a piping error, using >> instead of >. A code example would be nice.
精彩评论