This is a migrated thread and some comments may be shown as answers.

The given key was not present in the dictionary

2 Answers 261 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nigri
Top achievements
Rank 1
Nigri asked on 09 May 2014, 01:54 PM
Hi,

I'm with this problem in a report that I am unable to solve the problem 

I have these command gives the error and where this is 



protected void Form1_LoadCompleted_1()
{
try
            {
                System.Xml.XmlReaderSettings settings = new System.Xml.XmlReaderSettings();
                settings.IgnoreWhitespace = true;
                System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(this.MapPath("Rel_proposta_teste.trdx"), settings);


                Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer = new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();
                Telerik.Reporting.Report report = (Telerik.Reporting.Report)xmlSerializer.Deserialize(xmlReader);
                Rel.SetReportConnectionString(report, Convert.ToString(((Databases)Application["Databases"]).DataBaseList["Bdescala"].StringConnection)); <<<here problem>>>
                report.ReportParameters["Param_idproposta"].Value = Param_idproposta_inicio;


                // Atenção = altere o parâmetro “pld_entidade” para o parâmetro que vc criou no Reporting Telerik. 

                this.ReportViewer1.ReportSource = new Telerik.Reporting.InstanceReportSource
               {
                   ReportDocument = report,
               };

            }
            catch (Exception ex)
            {
                labError.Text = ex.Message.ToString();
            }
}


public partial class Rel : System.Web.UI.Page
{

public static void SetReportConnectionString(Telerik.Reporting.Report reportDocument, String connectionString)
        {
            Telerik.Reporting.SqlDataSource sds = (Telerik.Reporting.SqlDataSource)reportDocument.DataSource;
            if (sds != null)
                sds.ConnectionString = connectionString;
            SetReportConnectionString(reportDocument.Items, connectionString);
        }
        public static void SetReportConnectionString(Telerik.Reporting.ReportItemBase.ItemCollection items, String connectionString)
        {
            foreach (Telerik.Reporting.ReportItemBase ib in items)
            {
                if (ib.Items != null)
                {
                    SetReportConnectionString(ib.Items, connectionString);
                }
                Type type = ib.GetType();
                System.Reflection.PropertyInfo dataSourceProperty = type.GetProperty("DataSource");
                if (dataSourceProperty == null)
                    continue;
                var dataSource = dataSourceProperty.GetValue(ib, null) as Telerik.Reporting.SqlDataSource;
                dataSource.ConnectionString = connectionString;
            }
        }

}

The report is attached

thank you

NIgri

2 Answers, 1 is accepted

Sort by
0
Nigri
Top achievements
Rank 1
answered on 10 May 2014, 07:49 PM
My version is TelerikReporting Q1 2014

Thank you 

Nigri
0
KS
Top achievements
Rank 1
answered on 14 May 2014, 11:47 AM
Hi,

Give a shot to this - Changing the connection string dynamically according to runtime data.
And test to pass the connection string directly, without checking the database list, because it might be the problem.

-KS

Tags
General Discussions
Asked by
Nigri
Top achievements
Rank 1
Answers by
Nigri
Top achievements
Rank 1
KS
Top achievements
Rank 1
Share this question
or