Page 1 of 1

set connectionstring programmatically for stimulsoft dashboard

Posted: Thu Mar 26, 2020 2:18 pm
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

Re: set connectionstring programmatically for stimulsoft dashboard

Posted: Thu Mar 26, 2020 3:32 pm
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.

Re: set connectionstring programmatically for stimulsoft dashboard

Posted: Fri Mar 27, 2020 1:47 pm
by gheyasi.sk
thanks

Re: set connectionstring programmatically for stimulsoft dashboard

Posted: Mon Mar 30, 2020 12:43 pm
by Lech Kulikowski
Hello

We are always glad to help you!

Thank you.

Re: set connectionstring programmatically for stimulsoft dashboard

Posted: Wed Jan 19, 2022 6:20 am
by Pasindu
Hi,

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

Thank you

Re: set connectionstring programmatically for stimulsoft dashboard

Posted: Wed Jan 19, 2022 8:11 am
by Lech Kulikowski
Hello,

The same code:

Code: Select all

((StiMongoDbDatabase)report.Dictionary.Databases["Connection"]).ConnectionString = ""
Thank you.

Re: set connectionstring programmatically for stimulsoft dashboard

Posted: Wed Jan 19, 2022 9:47 am
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

Re: set connectionstring programmatically for stimulsoft dashboard

Posted: Wed Jan 19, 2022 11:57 am
by Lech Kulikowski
Hello,

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

Thank you.

Re: set connectionstring programmatically for stimulsoft dashboard

Posted: Thu Jan 20, 2022 2:43 am
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.

Re: set connectionstring programmatically for stimulsoft dashboard

Posted: Thu Jan 20, 2022 10:21 am
by Lech Kulikowski
Hello,

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

Thank you.