Page 1 of 1

Connect to database C#

Posted: Wed Oct 12, 2022 12:39 pm
by semaphore
Good Day,

I am attempting to connect to the database via C# code like:
report.Dictionary.Databases.Clear();
report.Dictionary.Databases.Add(new StiSqlDatabase("Connection", _configuration.GetConnectionString("ConnString")));
When attempting to run my report no data is returning, however when I embed the exact same connection string within the report itself and run the report from my code the data is returned. It appears that the connection string is not being used when passing it via the code method, I am using 2020.5.1 and will only be upgraded to the later version at the end of the year, early next.

Please advise what could be going wrong.

Re: Connect to database C#

Posted: Wed Oct 12, 2022 1:01 pm
by semaphore
I was able to resolve it myself, it turned out that inside the report the connection to the DB was aliased as SQL, in code I was using the string Connection. It appears the software is unable to infer a connection properly. Either way its resovled.

Re: Connect to database C#

Posted: Wed Oct 12, 2022 1:30 pm
by Lech Kulikowski
Hello,

Thank you for the information.