Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: First time an SQL expression is placed on report Post Reply Post New Topic
Author Message
jrstar
Newbie
Newbie


Joined: 05 May 2009
Online Status: Offline
Posts: 3
Quote jrstar Replybullet Topic: First time an SQL expression is placed on report
     Posted: 05 May 2009 at 11:36am

The same problem can be created using the normal Crystal Reports XI Release 2 developer environment and/or code (not only a code issue).

Symptom:

We dynamically auto generate SQL Expressions, Tables, Joins, Formula's and anything through C# and place it onto the Crystal Report through code via run-time user input in a web environment. I recieved a notification from one of my DB admins that crystal reports is causing massive memory consumption via unknown SELECT statements that have no joins and/or WHERE criteria.

Some Detective Work/More Info:

After using Microsoft "SQL Profiler" along with Crystal, I understand what is happening but don't know the "work around" to make Crystal stop executing the following SELECT scenario.

Anytime I create a new "SQL Expression" for the first time and then physically "drag and drop" it onto the report then Crystal is executing a "silent" SELECT statement against the database in the design environment. I'm calling it "silent" because I need MS SQL Profiler to see it happen. I'm guessing that this is used for validation or something but this is causing problems when automatically generating a report in a production environment.

Steps to re-create:
1. Open MS "SQL Profiler" and get it running. (will show Crystal Engine silently executes the SELECTS)
2. Add a new "SQL Expression" to your report.
3. Drag and Drop your new "SQL Expression onto your report
4. You will see that Crystal has created an SQL query and executed it against your database in design environment.

The Problem:

I can see under normal circumstances why you might want this funtionality (if it's actually used for the Crystal Engine to validate your SQL Expression). But, What also makes this functionality horrible is that on my behalf Crystal is creating these SELECT statements and using cross joins which is a major problem in a production environment. As a result, huge record sets are being created on our DB Server. I don't believe that this has any purpose in a production evironment when the cross-joins can create huge amounts of results just for the sake of Crystal Internally validating a new SQL Expression placed onto a report. It would be nice to disable this functionality in production. I don't know a "work around" since these SELECT queries are created on my behalf by the Crystal Engine at design time (via code auto generation in production).

Questions:
Can this functionality be disabled to prevent a production server from incurring the execution of these queries?
Anybody else notice this and have a "work around"?

IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 06 May 2009 at 7:08am
OK, the obvious question is:  If you are creating the SQL Expressions in C#, why bother passing them to the report which is going to hit the database, why not create a dataset or datatable and pass that to the report?
 
By passing the dataset to the report, the report no longer hits the DB server at all, your app does that.  As long as the data columns are the same, and they have to be to create a report, Crystal doesn't care where the data is coming from (just that it 'looks' right).  Create the report using a ADO.Net connection and your problems over 'silent' selects should be over.
IP IP Logged
jrstar
Newbie
Newbie


Joined: 05 May 2009
Online Status: Offline
Posts: 3
Quote jrstar Replybullet Posted: 06 May 2009 at 9:18am

That is defintely an interesting approach but would require a very sizable re-write (on my part) to make this happen. We have hundreds of tables, views, and tens of throusands lines of existing framework code just related to the generation process. I think your approach could be possibly looked at for future enhancement but probably not the "easy button" fix that I'm looking for (if one exists).

Have you ever heard anybody discussion about the validation process that I described in my first post? I searched the internet and didn't even find any discussion about it.  It would be nice if their was "semi-secret" registry setting, or crystal configuration setting that would allow me to disable that validation of SQL Expression in a production environment since it's already been tested in development and QA.  I tried all the options inside Crystal w/o any luck to disable validation.  I really do appreciate your suggestion though. It does have merit for future internal discussion.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 07 May 2009 at 6:37am
Sorry, I haven't.  Since I have never passed SQL into Crystal, I have either created the static report by joining to the tables or by using a stored proc, or most recently by passing disconnected recordsets, I am unfamiliar with this. 
 
I can understand that Crystal needs to validate the expression so that it can be assured that the columns that it needs are there, but one would think that there is an easier method.
 
Sorry, I couldn't be of more help.  I know changing the framework of an existing application is neither quick nor easy, and then there is changing all the reports...
IP IP Logged
jrstar
Newbie
Newbie


Joined: 05 May 2009
Online Status: Offline
Posts: 3
Quote jrstar Replybullet Posted: 08 May 2009 at 7:34am
If you don't mind. I'd like to ask you a question since you are familar with passing data into Crystal.
 
I found an example on Business Objects website on passing a DataSet from C# into Crystal and have it working on my laptop with my Table. It appears that the report can't have SQL Expressions otherwise the report will NOT generate. 
 
So, I'm trying to come up with a way to have a custom field in the SELECT statement and have it show up on the report as a field. Kind of like the way an SQL Expresion worked.
 
 So, in the below example I created a custom SQL field called TIMES7 in the query used to eventually fill the dataset

"Select CLM_ID, CLM, PAID_111X,  (PAID_111X * 7) As TIMES7 From WIKI.MULCRICKET WHERE CLM_ID < 5"

If I create a formula field in Crystal and set it's value to {MULCRICKET .TIMES7} then it works like a hybrid SQL Expression at run-time.
 
It works in run-time but in design time obviously error occur when the formula field is saved because the field doesn't really exists in the database table.
 
I was wondering what you usullay do in this scenario. My example is kind of a hack and was wondering if their was a best pratice for creating my own custom field in the query then having it placed into a field on the report.
 
 
 
 


Edited by jrstar - 08 May 2009 at 7:36am
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 11 May 2009 at 6:33am

I haven't done it that way.  If you know that you are going to create a field, just create the field.  When designing the report, you need to specify the data structure, in the case of a ADO.Net dataset, you would create a XSD file and create a Crystal connection to it.  When you do, the tables and fields in the dataset are available to you at design time.

If you ran your sql with the Times7 field, the report would fail because it is looking for a column in the table that doesn't exist.
 
What I do, is create my SQL statement in a stored proc.  My app then calls the stored proc and returns a dataset.  I stop the program and have the dataset write itself and the schema to the XSD file.  I then create the report using the XSD file...it is just like connecting to a table, all the columns and sample data are there.  When the report is done, I save it and have the application call the report.
 
Any changes in the data structure are handled the same way.  I get the dataset, write it out, and use this file to modify the existing report.
 
I hope this answers your question.
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum