Page 1 of 1

Change Database connection

Posted: Fri Nov 20, 2009 7:47 am
by whythetorment
Hi,

At work we have 3 servers. One is the live db, one is a development db, and the other is for user testing.

When we develop a report, the database is for example pointing to xx.xx.xx.193. Then our live database might point to xx.xx.xx.54.

In my report, I've set my SQL connection to dev. But when put the report live, we don't want to go change every report's db connection in the report self. We want it to use the connection that is in the application.

I've tried the following code, but can't get it to work (connection1 is my SQL connection

Code: Select all

Report.Load(ReportShareName & "MyReport.mrt")

Report.RegData("DataSource1", connection1)
Report.Compile()

Report.Item("@myParameter") = Textbox1.Text

Report.Render()
Report.Show()
In the report, DataSource1 is the name of my datasource. My connection name in the report is Connection, but that also didn't work when i had this :
Report.RegData("Connection", connection1).

How can I set the connection string at run time ?

Another thing, when I hover over connection1, it shows that it is connected to the db I want, so that is not the problem.

I also looked at the example SQLParameters, but that didn't help much. I don't want to clear my datasource, because Im guessing I would need to write my query again somewhere... which is bit pointless I guess. Want to use the query that is in my report.


Thanx.

Change Database connection

Posted: Fri Nov 20, 2009 11:06 am
by Jan
Hello,

You can use following code:

Code: Select all

report.Databases.Clear();
report.Databases.Add(new Stimulsoft.Report.Dictionary.StiOleDbDatabase("NameInReport", ConnectionString);
Thank you.

Change Database connection

Posted: Mon Nov 23, 2009 12:34 am
by whythetorment
Im getting a "Databases" is not a member of "Stimulsoft.Report.stiReport".

This is for VB and not C#.

Also, not sure if makes a difference but still using Version 2009.1.400 from 14 April 2009 coz that is the license the company purchased.

Change Database connection

Posted: Mon Nov 23, 2009 2:03 am
by Edward
Hi,

Sorry for that automatically error, please change the code as follows:

Code: Select all

report.Dictionary.Databases.Clear()
report.Dictionary.Databases.Add(New Stimulsoft.Report.Dictionary.StiOleDbDatabase("NameInReport", ConnectionString))
Thank you.

Change Database connection

Posted: Mon Nov 23, 2009 2:07 am
by whythetorment
I found this piece of code and seems to work well..

Code: Select all

TryCast(Report.Dictionary.Databases.Item("Connection"), Dictionary.StiSqlDatabase).ConnectionString = myconnectionstringhere
Thanx.

Change Database connection

Posted: Mon Nov 23, 2009 4:17 am
by Edward
Hi,

Yes, that is also possible.

Please let us know if any help is required.

Thank you.