Blazor - set connectionstring dynamically

Stimulsoft Reports.BLAZOR discussion
Post Reply
Jose
Posts: 16
Joined: Thu Oct 17, 2019 8:42 am

Blazor - set connectionstring dynamically

Post 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
Max Shamanov
Posts: 768
Joined: Tue Sep 07, 2021 10:11 am

Re: Blazor - set connectionstring dynamically

Post by Max Shamanov »

Hello,

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

Thank you.
Jose
Posts: 16
Joined: Thu Oct 17, 2019 8:42 am

Re: Blazor - set connectionstring dynamically

Post 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
Max Shamanov
Posts: 768
Joined: Tue Sep 07, 2021 10:11 am

Re: Blazor - set connectionstring dynamically

Post by Max Shamanov »

Hello,

Add

Code: Select all

@using Stimulsoft.Report.Dictionary
in your project.

Thank you.
Jose
Posts: 16
Joined: Thu Oct 17, 2019 8:42 am

Re: Blazor - set connectionstring dynamically

Post 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
Max Shamanov
Posts: 768
Joined: Tue Sep 07, 2021 10:11 am

Re: Blazor - set connectionstring dynamically

Post 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.
Jose
Posts: 16
Joined: Thu Oct 17, 2019 8:42 am

Re: Blazor - set connectionstring dynamically

Post by Jose »

Hi!

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

Regards
Attila
Max Shamanov
Posts: 768
Joined: Tue Sep 07, 2021 10:11 am

Re: Blazor - set connectionstring dynamically

Post by Max Shamanov »

Hello,

You are welcome!
Post Reply