views:

153

answers:

1

Hi,

I'm new to reporting so need some good information/resources to help me get some reports set up in our 3-tier app.

We currently have: UI (ASP.Net MVC 2 at present but also winforms in future), Business Logic and DAL (Entity Framework - Code-Only ie no edmx)

The BL has "manager" objects for selecting and manipulating entities.

Now I've started by creating a .rdlc report and have chosen as a data source an object which wraps the BL managers to retrieve the appropriate records.

Now I'm trying to add a front-end to see if my report works... I believe there's no good way to do a ReportViewer in a pure MVC way so I'm planning to use a .aspx webform. I've added the ReportViewer control but am unsure how to wire it up to my report...

I had expected to instantiate the report I created (which lives in the BL) and pass it to the viewer - But this doesn't seem to be the way it's supposed to work?

I've googled and have only found references to the ReportViewer either accessing a URL or a local file for the rdlc.

(For the moment, assume I don't have access to SSRS)

I don't see how either a local file OR a url helps me. If I were to point directly at the rdlc using a local path, I have no idea how I can properly initialise the ObjectDataSource - it relies on dependency injection and has a lot of dependencies.

If I point at a URL, I presumably need a reporting server up - and if the report lives on there, there's no way it can reference my business logic/DAL - Which means I'm maintaining 2 methods of accessing data in parallel - which seems awful to me.

I'm obviously approaching this wrong but most of the tutorials I can find assume the reports all live in the UI layer and have data sources specified on the webform itself - which is not what I need in this case. In theory, I should be able to provide a winforms front-end to the BL and have it generate exactly the same report with minimal effort.

Can someone please point me in the right direction.

Many thanks

In case it's relevant, I'm using .Net 4, VS2010, MVC 2 and IIS 7.

+1  A: 

As I said earlier, I do not do ASP so I don't know how resources used in such projects are deployed.
In WinForms projects, there are generally two options for deploying reports:

  • Embedded Resource (included in the output executable)
  • Content (Copied to the output directory)

Here is code that illustrates both procedures. It is an extract from my answer to your previous question.

With rptVwr.LocalReport
    'use this if the report is embedded in the project                     '
    'the name is of the following format [ProjectNamespace].[ReportName]   '
    .ReportEmbeddedResource = "ObjectReport.SampleReport.rdlc"

    'use the ReportPath if the report is stored somewhere else             '
    .ReportPath = "C:\Path\to\your\report" 'For demonstration purposes only'
End With

As you can see, when the report is embedded, you just assign the report as I illustrated in the accompanying comment.

I think, based on the nature of your project, you should set the report's Build Action in the Properties window as an embedded resource. That way, it can be accessed from wherever it is deployed.


Edit 1
I was looking through the MSDN Library and I found this article which covers server reports. Just scroll to the code section. I think it has what you're looking for.

There was also an article on CodeProject which covers your request extensively.

After skimming through, it appears you have to do the following:

  1. Set the report viewer's ProcessingMode property to Server.
  2. Enter the path (url) of the report in the ServerReport.ReportServerUrl property.
  3. Enter the location of the report in the ServerReport.ReportPath property.

Properties Window for Server Reports


Conclusion:

When deploying desktop applications, use the LocalReport property of the ReportViewer control and set the ProcessingMode to Local.
When deploying web-based projects use the ServerReoprt property of the ReportViewer control and set the ProcessingMode to Remote.

Alex Essilfie
Thanks for the detailed write-up. It's probably going to be tomorrow before I can try it out - I'll be back to you then.
Basiclife
Worked like a charm - thanks
Basiclife
Always a pleasure. Is there any other MS Report question bugging you?
Alex Essilfie
Not at present - "unfortunately", I've been pulled off reports for a week or two :D If I get any more, I'll comment here so you know :)
Basiclife