Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've some crystal reports, If the database table or column changed then I need to know those report's dataset are changed or not using c# code. For example I can manually right clicks the report's dataset then I can click "Verify Database". It will say "The databse is up to date". Same action I want to perform using c# code. Please share your ideas. Is this possible by c# code.

What I have tried:

I used VerifyDatabase method,

var analysisSuccess = true;
          var reportDocumentRc = new ReportDocument();

          try
          {
              this.Cursor = Cursors.WaitCursor;
              reportDocumentRc.Load(reportFileFullName);
              -----> reportDocumentRc.VerifyDatabase();


but it throws exception like "log on failed".
Posted
Updated 7-Feb-18 11:41am

1 solution

Crystal Reports do not save authentication details within the Report, you must provide them to the report as follows;
C#
ReportDocument rptDoc = new ReportDocument();
rptDoc.Load("Path and Filename of the Report");
// Create a Crystal ConnectionInfo object
CrystalDecisions.Shared.ConnectionInfo conRpt = new ConnectionInfo();
conRpt.ServerName = "DB Server";
conRpt.DatabaseName = "DB Name";
// use the below for SQL authentication
conRpt.IntegratedSecurity = false;
conRpt.UserID = "SQL Username";
conRpt.Password = "SQL Password";
// use the below if using Windows Authentication
// conRpt.IntegratedSecurity = true;

// Apply the connection information to the report tables
CrystalDecisions.CrystalReports.Engine.Tables tblsRpt = rptDoc.Database.Tables;
for(int i = 0; i < tblsTRpt.Count; i++)
{
    CrystalDecisions.CrystalReports.Engine.Table tblRpt = tblsRpt[i];
    CrystalDecisions.Shared.TableLogOnInfo infoTbl = tblRpt.LogOnInfo;
    infoTbl.ConnectionInfo = conRpt;
    tblRpt.ApplyLogOnInfo(infoTbl);
}
// If the Report contains sub reports you need to loop through each sub-report and apply the LogOnInfo to each Sub Report table

// you should now be able to Verify the database
rptDoc.VerifyDataBase();


Please note; VerifyDatabase does not return a value, hence I would expect that you will need to wrap the statement in a try/catch/finally & handle errors yourself

Hope this helps
 
Share this answer
 
Comments
MinionsVino 8-Feb-18 1:59am    
Thank you so much for your valuable comments, Is this only way to validate dataset in crystal report using c# code? Because the reason I'm asking, I've lot of crystal reports. If I loop through each its take long time.
an0ther1 8-Feb-18 17:09pm    
As far as I know, this is the only way of validating a report.
If you have that many reports you may want to think about some other method of identifying what reports should be updated or use stored procedures for your reports - this is my preference as it avoids this problem completely

Kind Regards
MinionsVino 13-Feb-18 9:47am    
It is void so it will not return any value then Can you tell me what is the purpose of "rptDoc.VerifyDataBase" ?
an0ther1 13-Feb-18 16:38pm    
Hi Minios,

I tested VerifyDatabase & it does nothing that I can see - even if I change the schema it returns nothing & does not throw an error.

As I said, you may want to change your reports to use Stored Procedures.
They are faster, especially when sub-reports are involved, and avoid the problem

Kind Regards
MinionsVino 14-Feb-18 3:09am    
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900