I want to use Stimulsoft report viewer to load reports using angular and .net core (.net5 actually).
I am having a hard time adding SQL connection string to the report.
I have followed their official documentation on how to do this but it doesn't work.
What happens when I use this is that ((StiSqlDatabase)report.Dictionary.Databases
throws a null reference exception.
This is how my code looks like
The other way I try to do this is report.Dictionary.Databases.Add(new StiSqlDatabase("ArchBD", "DataBaseConnectionString"));
This throws an exception with the message Format of the initialization string does not conform to specification starting at index 0
.
My connection string is like this: "Server=(localdb)\\mssqllocaldb; Database=MyDB; Trusted_Connection=True;"
I have used this format too: "Data Source=(localdb)\\mssqllocaldb;Initial Catalog=MyDB;Integrated Security=True;"
This one throws A network-related or instance-specific error occurred while establishing a connection to sql
var report = new StiReport();
var path = StiAngularHelper.MapPath(this, $"{report}.mrt");
report.Load(path);
var ConnectionString = ConnectionString;
var conn = new Stimulsoft.Report.Dictionary.StiSqlDatabase("MyDb", ConnectionString);
report.Dictionary.Databases.Add(conn);
Guys please help.
CodePudding user response:
I was able to solve it by looking at the report file and picked the right name for the connection name
<Dictionary Ref="1" type="Dictionary" isKey="true">
<Databases isList="true" count="1">
<ConnectionName Ref="2" type="Stimulsoft.Report.Dictionary.StiSqlDatabase" isKey="true">
<Alias>ConnectionName </Alias>
then used
((StiSqlDatabase)report.Dictionary.Databases["ConnectionName"]).ConnectionString = @"Data Source=server;Integrated Security=True;Initial Catalog=MyDB";