Search code examples
c#asp.netstimulsoft

Data source is not set in report of Stimulsoft generated in C#


Using C# + ASP.Net, I wrote this code:

    StiReport report = StiReport.CreateNewReport();
    try
    {                             
        report.Load(@"D:\Report.mrt");
        string Con = "Server=1.2.3.4;Persist Security Info=False;User ID=test;Password=test;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=True;";

        foreach (var item in x)
        {
            report.Dictionary.Databases.Clear();
            report.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("Connection", "Server=itc-hisreport;Persist Security Info=False;User ID=mumsadmin;Password=mUm$@d m(n52;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=True;")) ;
            
            using (SqlConnection connection = new SqlConnection(Con))
            {
                SqlCommand myCommand = new SqlCommand(item.DataSource, connection);
                SqlDataAdapter dataAdapter = new SqlDataAdapter(myCommand);
                DataSet dataSet = new DataSet("DataBase");
                dataAdapter.Fill(dataSet);                        
                report.RegData(dataSet);
                ((Stimulsoft.Report.Dictionary.StiSqlDatabase)(report.Dictionary.Databases[0])).ConnectionString = Con;

                report.Render(false);
            }
        }
            
    }
    catch (Exception ex)
    {
        //return (new BaseResult() { Message = ex.Message, Succseed = false });
    }

I have a blank .mrt which doesn't have any data source. After rendering and finishing this part, data sources are not set. Could you please guide me how can I set the connection for this file?

Regards


Solution

  • adding:

    report.Dictionary.Synchronize();
    

    after RegData function solved my problem!