[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1877
  • Last Modified:

Crystal Report 2008/ C# .Net Web App

I recently had to switch gears on my crystal reports and have the table names used be dynamic. I wrote a stored procedure to pass the table name as a parameter and that is now my datasource for the crystal reports. Works fine except you can't interact with the reports when viewing in the browser. I get the error "no valid report source" when I but logic in to handle postback. If I take it out works fine but it goes through the code to set the datasource each time the page loads which seems wrong to me but I'm not an expert. So I googled it and found a solution to add the crystal report to the session. Still not working; course I could have the code wrong to save it to the session. I was wondering what the most optimal and efficent way is to handing vary table names. The server and database are always the same but the table names are different per user. Also if I am actually doing it correctly by using a parameter for the table name how do i solve the error?
if (!Page.IsPostBack)
       {
           CrystalDecisions.CrystalReports.Engine.ReportDocument cr = new
   CrystalDecisions.CrystalReports.Engine.ReportDocument();
           cr.Load(@"~\OrdByDate.rpt");
           cr.SetParameterValue(0, tablename);
           cr.SetParameterValue(1, "11/01/2008");
           cr.SetParameterValue(2, "11/05/2008");
           CrystalReportViewer1.ReportSource = cr;
           CrystalReportViewer1.DataBind();
           Session.Add("cr", cr);
       }
       if (Page.IsPostBack)
       {
           ReportDocument cr = (ReportDocument)(Session["cr"]);  
       }

Open in new window

0
national_fulfillment
Asked:
national_fulfillment
  • 7
  • 6
  • 4
2 Solutions
 
Bob LearnedCommented:
I don't believe that Crystal Reports works well with dynamic table names.  I can't see what the data source is for the report.  

My preference is something like this:

1) Connect the Crystal Report to a schema document that defines the static table elements.

2) Layout the report as required

3) Get a DataSet with the table elements that I need, and change the name of the table elements for the DataSet, instead of passing in the table name as a parameter.

4) This would mean, though, that the tables would need the same schema structure
0
 
mlmccCommented:
I agree.  It is fairly straight forward to change the database but tables are different.

Here is an example of the push method TheLearnedOne is referring to

http://www.emoreau.com/Entries/Articles/2006/09/Feeding-Crystal-Reports-from-your-application.aspx

mlmcc
0
 
Bob LearnedCommented:
Thanks, Mike, for pointing out Eric's web site *GRIN*.
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
national_fulfillmentAuthor Commented:
thanks for the suggestions. I'll go check out the URL and see if I can get it working. Ohhhh wait so changing the database is pretty easy and efficent? Do either of you have examples of that. I could just as easy set up each client with their own database with the table names remaining the same. Im really concerned about efficency so what would you suggest for optimal performance?
0
 
mlmccCommented:
It is easier and more reliable to use the push method.

mlmcc
0
 
Bob LearnedCommented:
In my humble opinion Crystal Reports doesn't handle the "pull" method very well, since it stores static information in the Crystal Report object that is difficult to change, so with the "push" method you have more control over how the data is retrieved.  You would use the ReportDocument.SetDataSource method to pass any object the implements the IList interface, which includes a DataSet, DataTable, or a generics list of business objects (i.e. BindingList<BusinessObject>).
0
 
national_fulfillmentAuthor Commented:
so you both agree the "push method" mention in the article suggested is the most efficent way to fill the reports and not cause havoc on my web server? My datasources are fairly large with mutiple joins ect and since I'm starting out from scratch I want to do it correct from the beginning.
0
 
mlmccCommented:
Yes.  

mlmcc
0
 
Bob LearnedCommented:
Yes, "Push" instead of "Pull" with Crystal Report, and keep in mind that mlmcc is the resident Crystal Reports/Business Objects/Crystal Decisions/SAP Business Objects genius, and his opinion should care a lot of weight.
0
 
national_fulfillmentAuthor Commented:
Sweet I'll give the article a shot and go with the "push" method. Thanks both for your opinion.
0
 
national_fulfillmentAuthor Commented:
I know I closed this out and everything but I was just looking at the book "Crystal Reports .Net Programming" and it was saying not to use the "push method" that crystal reports perform better using the pull method. I'm just really concerned because the project is still in the infant stages and I want to make sure I'm utilizing the best method, my datasets will be large and I don't want to the reports to hang.
Sorry to add on.
Thanks Again.
0
 
Bob LearnedCommented:
Did it give reasons (back up those statements) why you should use the "pull method"?  Everything you read in a book should not be taken as gospel, and everything that you here from others should not be taken as the absolute truth.  With all things in the software development, you need to question, and to see if it makes sense.  My push toward the "push" method is not about performance, but maintenance.  The Crystal Reports designer and report viewer have kludgey processes that you learn how to work around through time.
0
 
mlmccCommented:
I agree.  One of the most frequently asked questions here is
    How to change the datasource from an application.

The answers seem to have mixed results and there seems to be the opinion that you can't change the source from a application at least in some instances.

The Push method always uses the same "source" if you will.  The dataset created by the application.

mlmcc
0
 
national_fulfillmentAuthor Commented:
the book said the reports perform better with the pull method. I have two concerns performance and maintance. I was just throwing it out there looking for some ray of light or best practice.
0
 
Bob LearnedCommented:
I don't know if there is any bench-marking or performance gains that are measured between the pull and push method, and there might be some gains that you can realize, but maintenance has a much bigger impact in my book, since it is very difficult to change the connection information, and with development, test, quality, and production areas, we need to change connection string all the time.

Crystal Reports started as COM libraries, and in my opinion is still stuck in that mind set, so in COM there might have been a performance gain with pulling, rather than pushing, but I haven't seen any good reason.

The idea of using a schema document to map between a data source and the Crystal Reports is a much simpler way of designing reports, rather than all those connection and authentication issues that will inevitably creep in with the "pull" method.

One way of testing that theory is to design a small, test report to see what we mean.  Try it with the "push" method described, and then try it with a "pull" method.
0
 
national_fulfillmentAuthor Commented:
thats a good suggestion. I've already designed a few using the pull method. My problem arose when I didn't want to maintain fifty different crystal reports (since I have mutiple datasources). I'll utilize the pull and see how it goes, sorry for beating a dead horse. Thanks again for your time.
0
 
Bob LearnedCommented:
So, if you have already thought about not having 50 different reports because of multiple data sources, then you are starting to thinking about the pain point that is at the center of the "pull" method, versus the "push" method.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 7
  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now