New user trying to set up a dynamic connection string

Stimulsoft Reports.NET discussion
Post Reply
This_Reporter
Posts: 3
Joined: Thu Aug 16, 2012 12:36 pm

New user trying to set up a dynamic connection string

Post by This_Reporter »

I was able to successfully make a new connection to an existing database by entering the following connection string in the New Connection interface in the report designer:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Q:\Engineering\Microvellum\Jobs 2012\mdb test\Manufacturing Data\Part Labels_NEST.mdb;

The problem is that the portion of the path "Jobs 2012\mdb test\Manufacturing Data" will change every time a report rendering is required. From what I've gathered from reading the forums, it's not possible to use a "variable" or a "parameter" through the New Connection interface but there is a way to make a dynamic connection string through the code tab. When I view the code tab, I see my connection string information as follows:

Code: Select all

Me.Dictionary.Databases.Add(New Stimulsoft.Report.Dictionary.StiOleDbDatabase("Nest", "Nest", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Q:\Engineering\Microvellum\Jobs 2012"& _ 
"\mdb test\Manufacturing Data\Part Labels_NEST.mdb;", false))
Unfortunately, I don't know the first thing about writing code behind the reports. So, is there any way I can modify this code to make the connection string dynamic? Perhaps by prompting the user to enter part of the connection string? Thanks, in advance, for your assitance.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: New user trying to set up a dynamic connection string

Post by HighAley »

Hello.

You could change your connecting string with next code:

Code: Select all

((Stimulsoft.Report.Dictionary.StiSqlDatabase)(rep.Dictionary.Databases["YourConnectionName"])).ConnectionString = "YourNewConnectionString";
Thank you.
This_Reporter
Posts: 3
Joined: Thu Aug 16, 2012 12:36 pm

Re: New user trying to set up a dynamic connection string

Post by This_Reporter »

Hello,

Thanks for your response. Please correct me if I am wrong, but the part of the code "YourNewConnectionString" is still a hard-coded string, right? I need to be able to change the string every time the report is rendered (without having to modify the code--as it is not feasible for the end user to change the code each time). Is there any way to accomplish this? Can I use a variable or a parameter in the code that represents the connection string that can be changed either automatically based on information in the report or manually by prompting the user for an input?
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: New user trying to set up a dynamic connection string

Post by HighAley »

Hello.

You could any string variable or function that returns string instead of "YourNewConnectionString".

Thank you.
Post Reply