Page 1 of 2
Common Data connection
Posted: Sat Jun 30, 2018 3:58 pm
by JohnW
I have a about 50 reports that share a common data connection. In each report I set the connection. As I move from dev to production I am now faced with changing the connection string for each of those reports. Was or is there a better way to handle this? Can I do something like placing the connection string on the web.config so I can change it once and not in each of the reports?
Now would be the time for me to do this if I can.
Anyone have a suggestion?
Thanks
Re: Common Data connection
Posted: Sat Jun 30, 2018 9:51 pm
by HighAley
Hello, John.
You can change the connection string with the next code:
Code: Select all
((StiSqlDatabase)report.Dictionary.Databases["Connection"]).ConnectionString = connectionString;
Thank you.
Re: Common Data connection
Posted: Mon Jul 02, 2018 6:21 pm
by JohnW
Thanks for the help I will give this a try
Re: Common Data connection
Posted: Mon Jul 02, 2018 9:40 pm
by HighAley
Hello.
We are always glad to help.
Let us know if you need additional help.
Thank you.
Re: Common Data connection
Posted: Sat Sep 22, 2018 4:46 pm
by JohnW
Sorry for being so slow to ask this followup question. Competing priorities.
Where is this line of code placed? I am not sure where it goes or if I need to create something. Would it go in the "ViewerXX_GetReport" event on Page Load? If so does it use this connection string in lieu of what is in the template?
Thanks
John
Re: Common Data connection
Posted: Mon Sep 24, 2018 8:01 am
by Lech Kulikowski
Hello,
You should use that code after loading report and before rendering.
Thank you.
Re: Common Data connection
Posted: Sun Sep 30, 2018 6:23 pm
by JohnW
Lech
I have placed following code in the xxxx_GetReport event. I had to convert the code you supplied to VB. When it runs I get an error stating the Report is not Specified on the DirectCast... line of code. It appears to not be is not seeing the object, which I assume is the report.
When I comment out this section of code, the report runs fine but using the built in connection string. I need to override those strings with a new one that can pass to any of the 50 reports as they are called. Ideally I would be able to place the connection string in the Web.config file as I do with other data connections.
I suppose I could have made an error in the conversion from C# to VB.
Any suggestions are appreciated.
-----------------------------------------------------------------------------
Dim report As New StiReport
Dim path As String = Server.MapPath("Reports/" & rptNew)
report.Load(path)
Dim connectionString as string = "Data Source=tssdca8430mddbs.xxx ;Initial Catalog=xxxx;User Id=xxxxadmin;Password='xxxx';" providerName="System.Data.SqlClient"
DirectCast(report.Dictionary.Databases("Connection"), Stimulsoft.Report.Dictionary.StiSqlDatabase).ConnectionString = connectionString
e.Report = report
----------------------------------------------------------------------
Re: Common Data connection
Posted: Mon Oct 01, 2018 6:14 am
by Lech Kulikowski
Hello,
Please send us your report for analysis.
Thank you.
Re: Common Data connection
Posted: Mon Oct 01, 2018 1:37 pm
by JohnW
Lech
Its not a single report. I want to overwrite/change the data connection used in creating the reports with test data, to one providing production data at run time. I have 50 + reports to do this for. I have a single viewer and the it loads the report the user has selected. As it loads I need the connection string overwritten/changed via code to the production database.
I would think its more of a viewer code issue and passing the correct correction string value.
Sadly, I cannot provide access to the production data. It is not accessible outside of the clients system.
I can change each report, but that seems the less desirable way over the long term.
Re: Common Data connection
Posted: Mon Oct 01, 2018 6:43 pm
by JohnW
Here is the code I have working at the moment. It is in VB for anyone who has a need.
Code: Select all
Dim rptNew As String
rptNew = Request.QueryString("rpt")
Dim connectionString As String = Your connection string
Dim report As New StiReport
Dim path As String = Server.MapPath("Reports/" & rptNew)
report.Load(path)
''Used to set connection string.
report.Dictionary.Databases.Clear()
report.Dictionary.Databases.Add(New Stimulsoft.Report.Dictionary.StiSqlDatabase("MS SQL", connectionString))