set connectionstring programmatically for stimulsoft dashboard

Stimulsoft Dashboards.WEB discussion
Post Reply
gheyasi.sk
Posts: 6
Joined: Tue Mar 24, 2020 7:26 am

set connectionstring programmatically for stimulsoft dashboard

Post by gheyasi.sk »

hi
i use from stimulsoft report 2020.2.1

for regular reports i use from below code for set connection string at runtime and work correctly.

Code: Select all

var report = StiReport.CreateNewDashboard();
report.Dictionary.Databases.Clear();
report.Dictionary.Databases.Add(new StiSqlDatabase("CRMConnection",Class.ConnectionString.GetSQLConnectionString()));
but this code not working for dashbords in stimulsoft

Can a code be used for regular reports and dashboards?

please help me
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: set connectionstring programmatically for stimulsoft dashboard

Post by HighAley »

Hello,

Please, try to use the next code to change the connection string:

Code: Select all

((StiSqlDatabase)report.Dictionary.Databases["Connection"]).ConnectionString = ""
Thank you.
gheyasi.sk
Posts: 6
Joined: Tue Mar 24, 2020 7:26 am

Re: set connectionstring programmatically for stimulsoft dashboard

Post by gheyasi.sk »

thanks
Lech Kulikowski
Posts: 6196
Joined: Tue Mar 20, 2018 5:34 am

Re: set connectionstring programmatically for stimulsoft dashboard

Post by Lech Kulikowski »

Hello

We are always glad to help you!

Thank you.
Pasindu
Posts: 3
Joined: Wed Jan 19, 2022 6:17 am

Re: set connectionstring programmatically for stimulsoft dashboard

Post by Pasindu »

Hi,

Can you please provide the relevant piece of code for a Stimulsoft dashboard using MongoDB database too?

Thank you
Lech Kulikowski
Posts: 6196
Joined: Tue Mar 20, 2018 5:34 am

Re: set connectionstring programmatically for stimulsoft dashboard

Post by Lech Kulikowski »

Hello,

The same code:

Code: Select all

((StiMongoDbDatabase)report.Dictionary.Databases["Connection"]).ConnectionString = ""
Thank you.
Pasindu
Posts: 3
Joined: Wed Jan 19, 2022 6:17 am

Re: set connectionstring programmatically for stimulsoft dashboard

Post by Pasindu »

Hi,

I used your code as follows:

Code: Select all

((StiMongoDbDatabase)report.Dictionary.Databases["Connection"]).ConnectionString = connectionstring; 
where the

Code: Select all

connectionstring
is the assigned connection string to the Database.

However the following exception is thrown:

Code: Select all

System.NullReferenceException: 'Object reference not set to an instance of an object.
'

Please Advice.

Thank you
Lech Kulikowski
Posts: 6196
Joined: Tue Mar 20, 2018 5:34 am

Re: set connectionstring programmatically for stimulsoft dashboard

Post by Lech Kulikowski »

Hello,

Please check your database name in the report and in the code, it should be the same.

Thank you.
Pasindu
Posts: 3
Joined: Wed Jan 19, 2022 6:17 am

Re: set connectionstring programmatically for stimulsoft dashboard

Post by Pasindu »

Hi,

The database names are the same. Could you please clarify if

Code: Select all

((StiMongoDbDatabase)report.Dictionary.Databases["Connection"]).ConnectionString = ""
, you mean to set it to an empty string

Code: Select all

""
or by

Code: Select all

""
you mean the connection string in our application?

Thank you.
Lech Kulikowski
Posts: 6196
Joined: Tue Mar 20, 2018 5:34 am

Re: set connectionstring programmatically for stimulsoft dashboard

Post by Lech Kulikowski »

Hello,

Should be:
((StiMongoDbDatabase)report.Dictionary.Databases["MongoDBConnectionName"]).ConnectionString = ""

Thank you.
Attachments
Screenshot 2022-01-20 112044.jpg
Screenshot 2022-01-20 112044.jpg (119.03 KiB) Viewed 1623 times
Post Reply