Reopen data transformation datasource problem

Stimulsoft Reports.NET discussion
Post Reply
Pavel K.
Posts: 3
Joined: Tue Dec 20, 2022 8:37 pm

Reopen data transformation datasource problem

Post by Pavel K. »

Hello. I have report, with data transformation datasource. I create report dynamic from my method, like this:

Code: Select all

public void MyMethod(TemplateDto template){
	using (var report = new StiReport())
	{
		report.Load(template.Data);
		SetConnectionStringToReport(report);
		report.Compile();
		SetParametersToReport(report);
		
		// For test getting datasource and view data
		StiDataTransformation dataTransformationSource = (StiDataTransformation)report.DataSources.Items.FirstOrDefault(x => x.Alias.Equals("MyDataTranform"));
                if (dataTransformationSource != null)
                {
                	// See data in my Data Transformation Source
                        var dataInSource = dataTransformationSource.RetrieveDataTable(Stimulsoft.Data.Engine.StiDataRequestOption.All);
                    }
             report.Render();
         }
}
When i call my method for the first time, my datasource open correctly and have correctly data (i see execute sql query in my database, from linked datasource). But next calls datasource not reopenning and datasource have data from first call. How i can update data manually in datasource?
Max Shamanov
Posts: 786
Joined: Tue Sep 07, 2021 10:11 am

Re: Reopen data transformation datasource problem

Post by Max Shamanov »

Hello,

Please send us the sample project that will let us trepoduces the issue.

Thank you.
Pavel K.
Posts: 3
Joined: Tue Dec 20, 2022 8:37 pm

Re: Reopen data transformation datasource problem

Post by Pavel K. »

Max Shamanov wrote: Wed Dec 21, 2022 9:36 am Hello,

Please send us the sample project that will let us trepoduces the issue.

Thank you.
Hello Max.

I created simple report, it include JSONdataSource, DataTransformation and two dataBands:
Снимок экрана 2022-12-21 210403.jpg
Снимок экрана 2022-12-21 210403.jpg (56.65 KiB) Viewed 629 times
Снимок экрана 2022-12-21 210323.jpg
Снимок экрана 2022-12-21 210323.jpg (24.53 KiB) Viewed 629 times
Снимок экрана 2022-12-21 210204.jpg
Снимок экрана 2022-12-21 210204.jpg (146.74 KiB) Viewed 629 times
And simple .Net project. My project generate random data, attaches this data to dataset and render report.
This operation calling three time. First time, value in transformdataband is correct. Next times this value not changing.
I use StimulSoft dll version 2022.1.1.0

Code: Select all

using Newtonsoft.Json;
using Stimulsoft.Report;
using Stimulsoft.Report.Dictionary;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace TestStimulSoftProject
{
    public class DtoTestData
    {
        public int Ident { get; set; }
        public string ParamName { get; set; }
        public int value { get; set; }

    }
    class Program
    {
        static string CreateDataFile()
        {
            
            var FileName = Path.ChangeExtension(Path.GetRandomFileName(), ".json");
            var DataList = new List<DtoTestData>();
            var random = new Random();
            for (var i = 0; i < 5; i++)
            {
                DataList.Add(new DtoTestData() { Ident = i, ParamName = $"Param #{i}", value = random.Next(0, 100) });
            }
            var json = JsonConvert.SerializeObject(DataList);
            File.WriteAllText(FileName, json);
            return FileName;
        }

        static void Main(string[] args)
        {
            
            CreateReport(1);
            CreateReport(2);
            CreateReport(3);
            CreateReport(4);
        }

        private static void CreateReport(int v)
        {
            Stimulsoft.Base.StiLicense.Key = "enter key here";

            var dataFile = CreateDataFile();
            using (var report = new StiReport())
            {
                report.Load("Report.mrt");
                var dataSource = (StiJsonDatabase)report.Dictionary.Databases.Items.FirstOrDefault(x => x.Name.Equals("JSONData"));
                dataSource.PathData = dataFile;
                report.Compile();
                report.Render();
                report.ExportDocument(StiExportFormat.ImageJpeg, $"report_{v}.jpeg");
            }
        }
    }
}
report_1.jpeg
report_1.jpeg (30.52 KiB) Viewed 629 times
report_2.jpeg
report_2.jpeg (30.53 KiB) Viewed 629 times
report_3.jpeg
report_3.jpeg (30.53 KiB) Viewed 629 times
report_4.jpeg
report_4.jpeg (30.54 KiB) Viewed 629 times
Attachments
Program.cs
(1.81 KiB) Downloaded 66 times
Report.mrt
(13.44 KiB) Downloaded 69 times
Pavel K.
Posts: 3
Joined: Tue Dec 20, 2022 8:37 pm

Re: Reopen data transformation datasource problem

Post by Pavel K. »

I think i found resolve this problem. Need clearing cache after report render

Code: Select all

	StiCacheCleaner.Clean(report);
Strange, I tried to disable caching but it didn't work.

Code: Select all

	report.CacheAllData = false;
        report.CacheTotals = false;
Max Shamanov
Posts: 786
Joined: Tue Sep 07, 2021 10:11 am

Re: Reopen data transformation datasource problem

Post by Max Shamanov »

Hello,

Yes, you should use the following code if you work with DataTransformation.

Code: Select all

StiCacheCleaner.Clean(report);
Post Reply