Common Data connection
Common Data connection
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
Now would be the time for me to do this if I can.
Anyone have a suggestion?
Thanks
Re: Common Data connection
Hello, John.
You can change the connection string with the next code:
Thank you.
You can change the connection string with the next code:
Code: Select all
((StiSqlDatabase)report.Dictionary.Databases["Connection"]).ConnectionString = connectionString;
Re: Common Data connection
Thanks for the help I will give this a try
Re: Common Data connection
Hello.
We are always glad to help.
Let us know if you need additional help.
Thank you.
We are always glad to help.
Let us know if you need additional help.
Thank you.
Re: Common Data connection
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
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
-
- Posts: 6254
- Joined: Tue Mar 20, 2018 5:34 am
Re: Common Data connection
Hello,
You should use that code after loading report and before rendering.
Thank you.
You should use that code after loading report and before rendering.
Thank you.
Re: Common Data connection
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
----------------------------------------------------------------------
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
----------------------------------------------------------------------
-
- Posts: 6254
- Joined: Tue Mar 20, 2018 5:34 am
Re: Common Data connection
Hello,
Please send us your report for analysis.
Thank you.
Please send us your report for analysis.
Thank you.
Re: Common Data connection
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.
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
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))