Page 1 of 1

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

Posted: Tue Mar 24, 2015 12:58 pm
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.

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

Posted: Tue Mar 24, 2015 1:32 pm
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.