Create multiple SSRS subscriptions but not multiple Schedules/Agent-Jobs

I need to create multiple SSRS report subscriptions but to avoid creating associated multiple Delivery Schedules and corresponding Agent Jobs (otherwise there are just too many Agent Jobs).
The plan is to use our own scheduling windows service. Later to execute/create the report I want to use
ReportingService2010.FireEvent Method
or exec ReportServer.dbo.AddEvent 'TimedSubscription', @SubscriptionGuid .
to invoke a subscription.
The question:
How to programmatically create multiple SSRS Subscriptions without creating multiple Delivery Schedules and associated multiple SQL Agent jobs?
al44ncAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SThayaTechnical MAnagerCommented:
Hi ,

 Please use the XQuery below to perform the above task

create	 PROCEDURE [dbo].[gsp_Email_XQUERY]  
AS    
BEGIN

--To DECLARE the Local Variable 

DECLARE @PARAMETERVALUES XML,@VDate VARCHAR(250),@FILENAME VARCHAR(MAX),
@RDLPath VARCHAR(MAX),@ItemID VARCHAR(250),@SbscrptnID VARCHAR(250),@newSubject VARCHAR(MAX)

--To Get the RDL path from catalog table from ReportServer

SET @RDLPath ='/Reports/Sym/Sym/EmailCAmounResolved'

 
select  @newSubject =  ' Report :  Email Contact Amount to Resolve Dashboard as on '+' '+ CONVERT(varchar(12), MAX(ReportDate),113)  FROM dbo. tbl1   


--Exportfile with Extn
SET @FILENAME=@newSubject

--To Get the ItemID from catalog table from ReportServer

SELECT @ItemID =  [ItemID] FROM ReportServer.dbo.[Catalog] 
WHERE PATH = @RDLPath

--To Get the SubscriptionID with the help of ItemID from catalog table 

SELECT  @SbscrptnID = Sch.[SubscriptionID]    
FROM   ReportServer.dbo.[ReportSchedule] Sch WITH (NOLOCK)
WHERE [ReportID] = @ItemID

--To SET Extension SETtings for the particular ID

SELECT @PARAMETERVALUES = ExtensionSETtings
FROM ReportServer.dbo.[Subscriptions]
WHERE  [DeliveryExtension] = 'Report Server Email' 
and SubscriptionID =@SbscrptnID

--Use X-Query to replace the existng values
 
SET @PARAMETERVALUES.modify('replace value of (/ParameterValues/ParameterValue/Value/text())[5] with sql:variable("@FILENAME")')

--Update the New File Name in [Subscriptions] table 

UPDATE ReportServer.dbo.[Subscriptions] 
SET ExtensionSETtings =CAST(CONVERT(XML,@PARAMETERVALUES,1) as NVARCHAR(MAX))
WHERE  [DeliveryExtension] = 'Report Server Email' 
and SubscriptionID =@SbscrptnID

--To Fire-up and Event based on the subscription ID
 
EXEC REPORTSERVER.DBO.ADDEVENT @EventType='TimedSubscription',@EVENTDATA=@SbscrptnID


END 

Open in new window

0
SThayaTechnical MAnagerCommented:
Hi ,

 Please use the XQuery below to perform the above task

create PROCEDURE [dbo].[gsp_XQUERY_FileShare]  
--@FileNAme Varchar(75)    
AS    
BEGIN

--To DECLARE the Local Variable 

DECLARE @PARAMETERVALUES XML,@VDate VARCHAR(MAX),@FILENAME VARCHAR(MAX),
@RDLPath VARCHAR(MAX),@ItemID VARCHAR(250),@SbscrptnID VARCHAR(250),@REPORTDATE datetime 


--To Get the RDL path from catalog table from ReportServer
--- use select * from catalog


SET @RDLPath ='/Reports/Sym/Sym/EmailCAmounResolved'

-- for Dynamic Filename 
SELECT @REPORTDATE=  MAX(ReportDate)   FROM dbo. tbl1   
--To Get the RDL path from catalog table from ReportServer
PRINT (@REPORTDATE)
--File Name with Date
 SET @VDate = REPLACE(CONVERT(varchar,@REPORTDATE,106),CHAR(32),'-')
 
 print @VDate
 SELECT @FILENAME ='Symantec EH Email Contact Amount to Resolve Dashboard'+@VDate+''

 

--Exportfile with Extn
SET @FILENAME=@FILENAME 


/*
Ex.
SELECT @FILENAME ='DellITSMotionTimeIntervalReport '+@VDate+''
*/


PRINT (@FILENAME)
 
--To Get the ItemID from catalog table from ReportServer

SELECT @ItemID =  [ItemID] FROM ReportServer.dbo.[Catalog] 
WHERE PATH = @RDLPath

--To Get the SubscriptionID with the help of ItemID from catalog table 

SELECT  @SbscrptnID = Sch.[SubscriptionID]    
FROM   ReportServer.dbo.[ReportSchedule] Sch WITH (NOLOCK)
WHERE [ReportID] = @ItemID

--To SET Extension SETtings for the particular ID

SELECT @PARAMETERVALUES = ExtensionSETtings
FROM ReportServer.dbo.[Subscriptions]
WHERE  [DeliveryExtension] = 'Report Server FileShare' 
and SubscriptionID =@SbscrptnID

--Use X-Query to replace the existng values
 
SET @PARAMETERVALUES.modify('replace value of (/ParameterValues/ParameterValue/Value/text())[2] with sql:variable("@FILENAME")')

--Update the New File Name in [Subscriptions] table 

UPDATE ReportServer.dbo.[Subscriptions] 
SET ExtensionSETtings =CAST(CONVERT(XML,@PARAMETERVALUES,1) as NVARCHAR(MAX))
WHERE  [DeliveryExtension] = 'Report Server FileShare' 
and SubscriptionID =@SbscrptnID

--To Fire-up and Event based on the subscription ID
 
EXEC REPORTSERVER.DBO.ADDEVENT @EventType='TimedSubscription',@EVENTDATA=@SbscrptnID
 
 
END 

Open in new window

0
SThayaTechnical MAnagerCommented:
Hi ,

  refer the above SQL query and do the below steps:

For Email Subscription:

1. please create a subscription
2. in  the sechdule section ...> select once and set the RDL to run for one time .

3. in the Email-XQUERY.sql Procedure set the correct RDL path ..This RDL Path (column Name "Path) you can get it from Select * from catalog in the reportserver DB

now your subscription runs one time and after that put a SQL a sql agent job and call the Email-XQUERY.sql stored Procedure ..

now you can put no.of sechdules in SQL agent by calling the Xquery Stored procedure
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

al44ncAuthor Commented:
SThaya,
Thank you for the postings, but they do not answer the question:
How to programmatically create multiple SSRS Subscriptions without creating multiple Delivery Schedules and associated multiple SQL Agent jobs?
0
al44ncAuthor Commented:
1) Create a Shared Schedule
2) get that Shared Schedule ID from Schedule table (where Type = 0) into @SharedScheduleID variable
3) Create a subscription using ReportingService2010.CreateSubscription Method providing  @SharedScheduleID value for the MatchData parameter. That will create a new subscription without new Schedule and Agent Job
4) Repeat step 3 any number of times creating multiple subscriptions without creating multiple Agent Jobs
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
al44ncAuthor Commented:
That's the only solution that actually answers the question.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SSRS

From novice to tech pro — start learning today.