Page 1 of 1

Blazor - set connectionstring dynamically

Posted: Thu May 12, 2022 5:07 pm
by Jose
Hi!

In MVC:
string connstr = GetStimulsoftConnString(something);
report.Dictionary.Databases.Clear();
report.Dictionary.Databases.Add(new StiSqlDatabase("MS SQL", connstr));
"MS SQL" is datasource in the Myreport.mrt.

How can I do this in Blazor? (error: StiSqlDatabase couldn't be found)

Thanks

Attila

Re: Blazor - set connectionstring dynamically

Posted: Fri May 13, 2022 9:44 am
by Max Shamanov
Hello,

We couldn't reproduce the issue.
Please send us a sample project that reproduces the issue.

Thank you.

Re: Blazor - set connectionstring dynamically

Posted: Fri May 13, 2022 10:24 am
by Jose
Hi Max!

I figured out a solution.
I have a request: 3173721 I send the project a few days ago.
If you insert these 3 lines (bold, italic - Set connectionstring), then you get the problem:

//Load report template
report.Load("Pages/BlazorReport.mrt");

// Set connectionstring
string connstr = "Data Source=PC\\INSTANCE1;Initial Catalog=DatabaseName;Integrated Security=False;Persist Security Info=True;User ID=usern;Password=passw;Connect Timeout=100";
report.Dictionary.Databases.Clear();
report.Dictionary.Databases.Add(new StiSqlDatabase("MS SQL", connstr));


//Render, w/out showing progress
report.Render(false);

Error: StiSqlDatabase could not be found.

In the mrt report, I set a connectionstring, but I have much database and I must set the appropriate one in the program.

Attila

Re: Blazor - set connectionstring dynamically

Posted: Fri May 13, 2022 11:50 am
by Max Shamanov
Hello,

Add

Code: Select all

@using Stimulsoft.Report.Dictionary
in your project.

Thank you.

Re: Blazor - set connectionstring dynamically

Posted: Fri May 13, 2022 4:44 pm
by Jose
Hi Max!

It's amazing. It works fine now. Thank you very much.

------------------------
I have another problem - I hope this is the last one for now.
Export to Html is OK.
Export to Pdf is not.
I set the text font in the report mrt to Cuorier New.

Error: Exception in PdfFonts.GetFontMetrics, font 'Courier New' step #10: 'Object reference not set to an instance of an object.'
2 lines:
- StiReportResponse.ResponseAsPdf(report);
- report.ExportDocument(Stimulsoft.Report.StiExportFormat.Pdf, _exportFilePath);

Why is that? (I need this feature very much.)

Thanks

Attila

Re: Blazor - set connectionstring dynamically

Posted: Mon May 16, 2022 12:56 pm
by Max Shamanov
Hello,

The AddFontFile() method does not modify the report.
It just adds a font file to a special collection and makes it accessible to our tool.

The PDF format is a fixed-layout format and all fonts should be the same.
So you see the issue in PDF only.

If you use Courier New font in your report, you need to load this font with StiFontCollection.AddFontFile(path, "Courier New") to export it in PDF without error.

Thank you.

Re: Blazor - set connectionstring dynamically

Posted: Tue May 17, 2022 8:59 am
by Jose
Hi!

OK.
I blowed it - copying fonts to my folder.
It works now.
Sorry.

Regards
Attila

Re: Blazor - set connectionstring dynamically

Posted: Tue May 17, 2022 10:54 am
by Max Shamanov
Hello,

You are welcome!