Unable to cast object of type 'Stimulsoft.Report.Dictionary.

Stimulsoft Reports.NET discussion
Post Reply
fuhrj
Posts: 120
Joined: Wed Jun 11, 2008 12:51 pm
Location: Lancaster, Ohio

Unable to cast object of type 'Stimulsoft.Report.Dictionary.

Post by fuhrj »

I am using reports.net in a web project with a web viewer and getting the following error on one report :

Code: Select all

Unable to cast object of type 'Stimulsoft.Report.Dictionary.StiVirtualSource' to type 'Stimulsoft.Report.Dictionary.StiSqlSource'.
System.InvalidCastException: Unable to cast object of type 'Stimulsoft.Report.Dictionary.StiVirtualSource' to type 'Stimulsoft.Report.Dictionary.StiSqlSource'.
In the code, I am manually setting the database and also overriding the command timeout:

Code: Select all

 StiReport report = new StiReport();
                    report.Load(filename);

                    if (report != null) {

                        reportTitle.Text = report.ReportName;

                        StiSqlDatabase db = (StiSqlDatabase)report.Dictionary.Databases[0];
                        db.ConnectionString = dbConnector.GetConnectionString();

                        report.Dictionary.Databases.Clear();
                        report.Dictionary.Databases.Add(db);

                        
                            foreach (StiDataSource ds in report.Dictionary.DataSources) {
                                //((StiSqlSource)report.Dictionary.DataSources["SqlSourceName"]).CommandTimeout = 6000;
                                ((StiSqlSource)ds).CommandTimeout = 120;
                            }
                        

                        webViewer.Report = report;

                    }

I suspect that the code that is failing is this:

Code: Select all

foreach (StiDataSource ds in report.Dictionary.DataSources) {
//((StiSqlSource)report.Dictionary.DataSources["SqlSourceName"]).CommandTimeout = 6000;
((StiSqlSource)ds).CommandTimeout = 120;
}
If this is the problem, is this the correct way to set the command timeout? A report may have multiple data sources which is why I used the foreach statement.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Unable to cast object of type 'Stimulsoft.Report.Diction

Post by Alex K. »

Hello,

Please try to use the following code:

Code: Select all

foreach (StiDataSource ds in report.Dictionary.DataSources)
{
    if (ds is StiSqlSource)
        ((StiSqlSource)ds).CommandTimeout = 120;
}
Thanky ou.
Post Reply