Link to home
Start Free TrialLog in
Avatar of sarolabelle
sarolabelle

asked on

SQL Report sent via email when user presses a button

Hello,

I don't need a solution, I just need a starting point.  

When I run a report from SQL report manager I run it for a certain user (userid is a parameter for the report).   I have an application.  What I would like to happen is when a user hits a button in the application the report is sent to them in an email.   How should I do this?  Or can this even be done?

Thanks.
Avatar of Chris McGuigan
Chris McGuigan
Flag of Canada image

What I'm about to suggest is probably not going to be supported, advised or encouraged by Microsoft.
Also I've not tried this myself.

My idea is to create a subscription record on the fly in the Subscription table in the ReportServer database.
There is a CreateSubscription stored procedure in there which is obviously what report manager uses.
On reflection, I would suggest actually that Microsoft probably wouldn't have a problem with this as the procedure looks reasonably developer friendly.

There is also a DeleteSubscription to remove it at a later time.

So create the subscription to trigger in a minute or two. And log the Id of the subscription record somewhere, then have a cleanup task overnight, deleting these subscriptions.

Cheers
Chris

Avatar of sarolabelle
sarolabelle

ASKER

Ok, great.  I did research and got as far as your last sentence.   How can I log the id and where?   If I save it in SQL then does the DeleteSubscription(subid) method work inside of SQL or perhaps I should create a service that runs at a certain time?  
ASKER CERTIFIED SOLUTION
Avatar of Chris McGuigan
Chris McGuigan
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you!  This was just the little push I needed to get me started!