Generating SSRS reports using C# program - c#

I have a situation where I need to generate SSRS report for each account holder. The vague idea that I am having is to write a C# Code that should get the list of account numbers as input and run the report for each account number and then store the report as a pdf in a location, that can be mailed to the respective account holders. Now I have an SSRS report that can run by inputting one account number. But how can I run this report in a kind of a loop for list of account numbers. Do I need to write a c# program that should in someway call the reports for each account number( and obviously this program should run at a specific time say 8P.M every day for instance). Is this idea possible to implement? I am totally struck at this point. Any help would be really appreciated.

Well. I googled and figured out that what I might need is an SSRS data driven subscription. But when I created one and scheduled to run at say 8P.M, its not running. And its not showing any error message in the description.

Old post, but possibly still relevant.
Two possible workarounds:
Write a C# program to call the ReportExecutionService webservice in a loop. You can call SetExecutionParameters() each time with an array of report parameters.
Write a C# program to use WebClient.DownloadFile in a loop with the url of the report. Report parameters can be part of the url.

Related

need help in generating report in c# wpf

I have a program which analyses some information in runtime and save the analysis results in certain variables. I have 15 of these variables, of which, 13 are string type, 1 integer and 1 bitmap image. I want to let the user to generate a report based on the analysis data. I have been trying to search the forums for help, but couldn't find a proper solution yet.
First of all, I don't want to save these analysed results in a database (SQL etc). All i want to do is just to display the report to the user based on analysis results and let him save or print it.
This is what I did so far based on numerous hints that I get from forums. I added a report.rdlc file and created a template for the report. I also created a dataset.xsd file and added the analysis parameters to the dataset. All the dataset values are added to the report template.
Now this is where I am stuck. I don't have an idea how to proceed from here and generate a report. Right now what my program does is, upon button click, the analysed parameters will be saved in their respective variables that I specified in the main program. What I want to achieve is to use these results and generate a report as in the template. Sorry that I am not able to post images here due to the user restriction.
Any guidance on how to achieve this is much appreciated.
Thank you!
From what I recall, reports support parameters which can be injected via the presentation control.
With little else to go on, I would look here first.

C# solution design to display web content from a complex calculation?

I need to process a complex calculation to generate a report and display as a webpage. It has to be run periodically to recalculate the formula based on new input.
I have a few ideas:
1. Create a web service to process and cache the content and then create a web application to request the content via HTTP periodically.
2. Create a service to output a file periodically and then create a web application to read the file.
3. Create a web application which has a task in there running periodically to generate the output and then create a webpage to display it.
I have read some of the old threads but I want to know which is the better approach, the pros and cons or if there are a newer way of implementing this?
JiTE!
I did a program that is similar to yours. The task is to generate a report when a user asks the application to do. Usually it is a daily report, but the calculation costs several minutes, for there are too many records, and the fomular is complex, too.
We created a periodly thread to check wether it is time to calucate.Thus the thread will calute and store the condition and result into SqlServer. When users click the button to view the daily report, yet the report is in DB and the application just needs to read it out from DB, and show it on the screen.
Let disscuss your solutions: solution 1 and 2 seems good, but sulution 3 does not match the DesignPatterns, because all tasks are put in a single application.
Hope everything goes well!
David Liu

printing bill in the preprinted paper using crystal report

I am working on the desktop application which needs to print the bill.I am currently using Visual Studio 10 and sql express as database.
I need to print the bill in the pre printed paper which has majority of the content.
I just need to add the customer name, some customer details and content of the bill which is saved in the database.
The pre printed bill has logo along with some basic information of the company....
so i need to fill the bill with name and search the data using stored procedure.
i will be grateful if anyone helped me in any way possible
Try scanning the hard copy paper into an image file, and setting that image file as the background on the report.
From there, just put a couple of the fields onto the report where it looks like they should go. Remove/hide the background and print a test page to find the offset. It should be pretty evident if the fields are generally a centimeter higher on the page than they should be. Then just adjust the fields accordingly.
I know it seems like a daunting task at first, but after the first one or two reports you will get the hang of it.
[Edit]
In the report itself, hide the header and footer and set the detail height to 7.5 (or whatever the full page height is, taking into account margins). Pass the report exactly one record with the values that need to be printed.
You may also consider using SQL Server Reporting Services (SSRS) instead of Crystal Reports. Crystal can be tricky to deploy with desktop applications. SSRS Express is free. You will just need to install SQL Server Express with Advanced Services.

how to write to text file constantly while site is live

What I'm trying to do is create an asp.net page that runs a random number generator, displays the random number, and writes it to a text file. That part is no worries, the issues is I want the number generation and file writing to continue while the page is live - ie if no one is actually viewing the page, it's just sitting on the server, the process should continue.
Is this possible?
EDIT: Foolishly overlooked using a webservice to generate the number - I've knocked up a basic service that generates a number and writes it to a text file. Can't work out how to schedule/automate it - could I set up a timer, with a given interval, then use timer_Tick?
Scheduling is new to me, any advice is appreciated.
You can use Window Service to work in backgroud, please see below link:
http://www.codeproject.com/KB/dotnet/simplewindowsservice.aspx
http://www.codeguru.com/columns/dotnet/article.php/c6919
Have you considered the use of scheduled tasks? So, rather than the page calling the updates, the scheduled task does that, and the page viewer is just seeing "latest results" at any specific point. Of course, that may not be feasible, but by the sounds of it, you're after a constantly working service/task with an ability to view the latest number, a little like an RSA token which shows new numebrs even if you dont need one.
Not sure if this is what you want. But if you are interested in using a scheduler for this task, you can try Quartz.Net. It is a very popular, full-featured and open source sheduling system.
Please describe what you are trying to achieve. There might be a better way than writing random numbers to a file.
I would not use a service (web or winservice) for this. There is no benefit to use a webservice since it will just do exactly the same as your web would do. A windows service will continue to run independent of your web, and you need to create some kind of IPC and to keep track of several timers/files.
The easiest way to do this is to use a System.Threading.Timer and keep it in a session variable. Also note that you need to kill it when the user session expires.
You should also be aware of that one timer will be created per user that uses the page.
Update
Create a Windows Service application and add a System.Threading.Timer to it. Write to the file in the timer callback.
Then open the textfile in your web app (using FileShare.ReadWrite + FileMode.Read)

How to restrict download options on a single report in SSRS?

This question asks how to restrict for a whole server. I just want to do so for a single report. I found a code snippet but it doesn't provide any clues on how to implement:
foreach (RenderingExtension extension in this.reportViewer.LocalReport.ListRenderingExtensions()) {
if (extension.Name == "PDF") {
((Extension)(extension.GetType().GetField("m_serverExtension", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(extension))).Visible = false;
}
I can't see how to make the report reference this code upon loading. Does anyone know how I am supposed to make the report execute this code?
EDIT: Incidentally report access is through the SSRS Report Manager web app. We are, in the main, delighted with this product so wouldn't consider reinventing the wheel in order to implement a hack to produce what is, essentially a "would be nice" feature.
It still boggles the mind slightly that the report's available rendering options are not controllable at the report level. Ho hum.
Incidentally I found this blog entry which clarifies the above code a little. Turns out we're talking about using a reportviewer component to limit the export options. Apparently this requires a dirty, dirty hack and besides it's not how we want to run our reporting function.
So unless anyone has a better idea than this within the next fortnight I'll mark this as the answer which basically sums up to:
You can only restrict functionality like this under certain conditions and by no means easily even when you do.
This seems like a clear failure in the wider fitness of SSRS for purpose as we have users who require Excel export functionality and users who need to be limited to PDF only. Oh well.
Does it matter?
Once they've downloaded the data and taken it offsite, you've lost it anyway.
You haven't really described how you are calling the reports - have you created some kind of application? Are you actually using the report viewer control?
You can generate a report in a specific format using the report URL and including the rs:Format parameter, e.g.
http://SERVER/reportserver?%2fSomeFolder%2fSomeReport&rs:Command=Render&rs:Format=PDF
The above URL generates the report as a PDF. You can also use the URL to hide the report toolbar etc. so you could create these URLs as links in your application, maybe one using just rs:Command=Render as a "View Report" link and one link that includes rs:Format=PDF as an "Export to PDF" link.
More on Reporting Services URL access.

Categories