Missing the benefit of DataSets with Crystal 10 with process reload on Next|Previous button activiat

D

dekern

Good afternoon all,

I guess I am missing the benefit of using datasets with Crystal. For
years I have written wrapper apps that used the Pull method and I let
Crystal do all the sql work. Now I have an issue where the queries run
for 4+ minutes so I don't want Crystal doing repeated legwork.

I was under the impression that once the DataSet is filled and bound to
the report the report (crystalviewer) would not need to re-run the
query - thus speeding up paging and such.

The way I have my code set up now, following the scores of examples,
everytime I hit the Next|Previous button in the CrystalViewer the code
is regenerated and the dataset is filled, and the crystalviewer is
assigned and the report takes the same amount of time to move to the
next page as it did on its initial load. I have confirmed that the
acquiring of information and modifying of sql querries on the fly is
working so I am happy with the dataset process itself but I am
dissappointed in the way it is supposedly implemented.

All of the sample code I have seen states to put the dataset and report
object code at the following:

"After the call to InitializeComponent() in PageInit()"

When I put my code inside PageInit() it is called repeatedly whenever
the Next|Previous button is selected. I've tried installing the code
inside the Page_Load() method but it too is called every time the
Next|Previous button is called.

Am I wrong in my believing that this process of creating a dataset,
filling it, assigning it using SetDataSource() method is unneccessary
and detrimental to performance?

Could someone please steer me in the right direction on this - I
believe it is a matter of placing my code in the proper place or
processing the Next|Previous response differently to avoid rebuilding
the report and re-running the dataset build.

Dave


CODE:

override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);

// If we have an error in that the report template name is
// set to "error.rpt" then DON'T try to set parameter or connection
info.
if( this.reportDocument1.FileName.IndexOf("error.rpt") == -1 )
{
if( this.reportDocument1.Subreports.Count > 0 )
setsubreportparaminfo();
setvieweroptions();
}

// set up connection information
string myConnString = "Server="
+ cfgFile.getserver().Trim()
+ ";Trusted_Connection=no" // + cfgFile.getconntype().Trim()
+ ";Database=" + cfgFile.getdatabase().Trim()
+ ";UID=" + HttpContext.Current.Session["UserID"]
+ ";PWD=" + HttpContext.Current.Session["Password"];

SqlConnection sqlConn = new SqlConnection(myConnString);

SqlDataAdapter dataAdapter = new SqlDataAdapter();

dataAdapter.SelectCommand = new SqlCommand(this.buildQuery(),
sqlConn);

DataSet dataSet = new DataSet();

// Connect to, fetch data, and disconnect from database
int rowcount = dataAdapter.Fill (dataSet);

// Use Report Engine object model to pass
// populated dataset to report
this.reportDocument1.SetDataSource (dataSet);

setparaminfo( this.reportDocument1 );
this.CrystalReportViewer1.ReportSource = this.reportDocument1;
}
 
G

Greg Young

Try caching your dataset .. then hand back the dataset when it asks for it
again.

your code would then become.

if(!Cache.Contains("my data")) {
Cache["mydata"] = GetMyDataSet();
}
return Cache["mydata"];

This should speed you up immensely.

Cheers,

Greg Young
MVP - C#
http://geekswithblogs.net/gyoung
dekern said:
Good afternoon all,

I guess I am missing the benefit of using datasets with Crystal. For
years I have written wrapper apps that used the Pull method and I let
Crystal do all the sql work. Now I have an issue where the queries run
for 4+ minutes so I don't want Crystal doing repeated legwork.

I was under the impression that once the DataSet is filled and bound to
the report the report (crystalviewer) would not need to re-run the
query - thus speeding up paging and such.

The way I have my code set up now, following the scores of examples,
everytime I hit the Next|Previous button in the CrystalViewer the code
is regenerated and the dataset is filled, and the crystalviewer is
assigned and the report takes the same amount of time to move to the
next page as it did on its initial load. I have confirmed that the
acquiring of information and modifying of sql querries on the fly is
working so I am happy with the dataset process itself but I am
dissappointed in the way it is supposedly implemented.

All of the sample code I have seen states to put the dataset and report
object code at the following:

"After the call to InitializeComponent() in PageInit()"

When I put my code inside PageInit() it is called repeatedly whenever
the Next|Previous button is selected. I've tried installing the code
inside the Page_Load() method but it too is called every time the
Next|Previous button is called.

Am I wrong in my believing that this process of creating a dataset,
filling it, assigning it using SetDataSource() method is unneccessary
and detrimental to performance?

Could someone please steer me in the right direction on this - I
believe it is a matter of placing my code in the proper place or
processing the Next|Previous response differently to avoid rebuilding
the report and re-running the dataset build.

Dave


CODE:

override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);

// If we have an error in that the report template name is
// set to "error.rpt" then DON'T try to set parameter or connection
info.
if( this.reportDocument1.FileName.IndexOf("error.rpt") == -1 )
{
if( this.reportDocument1.Subreports.Count > 0 )
setsubreportparaminfo();
setvieweroptions();
}

// set up connection information
string myConnString = "Server="
+ cfgFile.getserver().Trim()
+ ";Trusted_Connection=no" // + cfgFile.getconntype().Trim()
+ ";Database=" + cfgFile.getdatabase().Trim()
+ ";UID=" + HttpContext.Current.Session["UserID"]
+ ";PWD=" + HttpContext.Current.Session["Password"];

SqlConnection sqlConn = new SqlConnection(myConnString);

SqlDataAdapter dataAdapter = new SqlDataAdapter();

dataAdapter.SelectCommand = new SqlCommand(this.buildQuery(),
sqlConn);

DataSet dataSet = new DataSet();

// Connect to, fetch data, and disconnect from database
int rowcount = dataAdapter.Fill (dataSet);

// Use Report Engine object model to pass
// populated dataset to report
this.reportDocument1.SetDataSource (dataSet);

setparaminfo( this.reportDocument1 );
this.CrystalReportViewer1.ReportSource = this.reportDocument1;
}
 
D

dekern

Thanks for the response Greg.

So just where would I place this code?, as the first line in the
OnInit() method?

Dave


Greg said:
Try caching your dataset .. then hand back the dataset when it asks for it
again.

your code would then become.

if(!Cache.Contains("my data")) {
Cache["mydata"] = GetMyDataSet();
}
return Cache["mydata"];

This should speed you up immensely.

Cheers,

Greg Young
MVP - C#
http://geekswithblogs.net/gyoung
dekern said:
Good afternoon all,

I guess I am missing the benefit of using datasets with Crystal. For
years I have written wrapper apps that used the Pull method and I let
Crystal do all the sql work. Now I have an issue where the queries run
for 4+ minutes so I don't want Crystal doing repeated legwork.

I was under the impression that once the DataSet is filled and bound to
the report the report (crystalviewer) would not need to re-run the
query - thus speeding up paging and such.

The way I have my code set up now, following the scores of examples,
everytime I hit the Next|Previous button in the CrystalViewer the code
is regenerated and the dataset is filled, and the crystalviewer is
assigned and the report takes the same amount of time to move to the
next page as it did on its initial load. I have confirmed that the
acquiring of information and modifying of sql querries on the fly is
working so I am happy with the dataset process itself but I am
dissappointed in the way it is supposedly implemented.

All of the sample code I have seen states to put the dataset and report
object code at the following:

"After the call to InitializeComponent() in PageInit()"

When I put my code inside PageInit() it is called repeatedly whenever
the Next|Previous button is selected. I've tried installing the code
inside the Page_Load() method but it too is called every time the
Next|Previous button is called.

Am I wrong in my believing that this process of creating a dataset,
filling it, assigning it using SetDataSource() method is unneccessary
and detrimental to performance?

Could someone please steer me in the right direction on this - I
believe it is a matter of placing my code in the proper place or
processing the Next|Previous response differently to avoid rebuilding
the report and re-running the dataset build.

Dave


CODE:

override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);

// If we have an error in that the report template name is
// set to "error.rpt" then DON'T try to set parameter or connection
info.
if( this.reportDocument1.FileName.IndexOf("error.rpt") == -1 )
{
if( this.reportDocument1.Subreports.Count > 0 )
setsubreportparaminfo();
setvieweroptions();
}

// set up connection information
string myConnString = "Server="
+ cfgFile.getserver().Trim()
+ ";Trusted_Connection=no" // + cfgFile.getconntype().Trim()
+ ";Database=" + cfgFile.getdatabase().Trim()
+ ";UID=" + HttpContext.Current.Session["UserID"]
+ ";PWD=" + HttpContext.Current.Session["Password"];

SqlConnection sqlConn = new SqlConnection(myConnString);

SqlDataAdapter dataAdapter = new SqlDataAdapter();

dataAdapter.SelectCommand = new SqlCommand(this.buildQuery(),
sqlConn);

DataSet dataSet = new DataSet();

// Connect to, fetch data, and disconnect from database
int rowcount = dataAdapter.Fill (dataSet);

// Use Report Engine object model to pass
// populated dataset to report
this.reportDocument1.SetDataSource (dataSet);

setparaminfo( this.reportDocument1 );
this.CrystalReportViewer1.ReportSource = this.reportDocument1;
}
 
G

Greg Young

Yes in your oninit method ..



dekern said:
Thanks for the response Greg.

So just where would I place this code?, as the first line in the
OnInit() method?

Dave


Greg said:
Try caching your dataset .. then hand back the dataset when it asks for
it
again.

your code would then become.

if(!Cache.Contains("my data")) {
Cache["mydata"] = GetMyDataSet();
}
return Cache["mydata"];

This should speed you up immensely.

Cheers,

Greg Young
MVP - C#
http://geekswithblogs.net/gyoung
dekern said:
Good afternoon all,

I guess I am missing the benefit of using datasets with Crystal. For
years I have written wrapper apps that used the Pull method and I let
Crystal do all the sql work. Now I have an issue where the queries run
for 4+ minutes so I don't want Crystal doing repeated legwork.

I was under the impression that once the DataSet is filled and bound to
the report the report (crystalviewer) would not need to re-run the
query - thus speeding up paging and such.

The way I have my code set up now, following the scores of examples,
everytime I hit the Next|Previous button in the CrystalViewer the code
is regenerated and the dataset is filled, and the crystalviewer is
assigned and the report takes the same amount of time to move to the
next page as it did on its initial load. I have confirmed that the
acquiring of information and modifying of sql querries on the fly is
working so I am happy with the dataset process itself but I am
dissappointed in the way it is supposedly implemented.

All of the sample code I have seen states to put the dataset and report
object code at the following:

"After the call to InitializeComponent() in PageInit()"

When I put my code inside PageInit() it is called repeatedly whenever
the Next|Previous button is selected. I've tried installing the code
inside the Page_Load() method but it too is called every time the
Next|Previous button is called.

Am I wrong in my believing that this process of creating a dataset,
filling it, assigning it using SetDataSource() method is unneccessary
and detrimental to performance?

Could someone please steer me in the right direction on this - I
believe it is a matter of placing my code in the proper place or
processing the Next|Previous response differently to avoid rebuilding
the report and re-running the dataset build.

Dave


CODE:

override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);

// If we have an error in that the report template name is
// set to "error.rpt" then DON'T try to set parameter or connection
info.
if( this.reportDocument1.FileName.IndexOf("error.rpt") == -1 )
{
if( this.reportDocument1.Subreports.Count > 0 )
setsubreportparaminfo();
setvieweroptions();
}

// set up connection information
string myConnString = "Server="
+ cfgFile.getserver().Trim()
+ ";Trusted_Connection=no" // + cfgFile.getconntype().Trim()
+ ";Database=" + cfgFile.getdatabase().Trim()
+ ";UID=" + HttpContext.Current.Session["UserID"]
+ ";PWD=" + HttpContext.Current.Session["Password"];

SqlConnection sqlConn = new SqlConnection(myConnString);

SqlDataAdapter dataAdapter = new SqlDataAdapter();

dataAdapter.SelectCommand = new SqlCommand(this.buildQuery(),
sqlConn);

DataSet dataSet = new DataSet();

// Connect to, fetch data, and disconnect from database
int rowcount = dataAdapter.Fill (dataSet);

// Use Report Engine object model to pass
// populated dataset to report
this.reportDocument1.SetDataSource (dataSet);

setparaminfo( this.reportDocument1 );
this.CrystalReportViewer1.ReportSource = this.reportDocument1;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top