-
Notifications
You must be signed in to change notification settings - Fork 199
Set Connection String Runtime
dotnet add package Majorsilence.Reporting.RdlViewer
Using a dynamic connection string in My-FyiReporting is easy and simple but it does require a few steps.
The following will describe the steps necessary to dynamically set the connection strings. Examine the screenshots below for more details.
These instructions will add a new report parameter called ConnectionString that will be set in c# or vb.net code.
- Open the report in the designer
- In the properties panel make sure "Report" is selected
- Find the "Parameters" and click the "..." load button
- In the parameter window that opens click "Add"
- Enter a name
- If you want to prompt the user with the builtin prompt enter a prompt
- Set the datatype to "String"
- Click OK
- Back in the main designer go to the menu Data -> Data Sources
- Select the data source whose connection should be set by the parameter
- Either clear out the connection string and type in the parameter or
- Click the "fx" button
- Clear the connection string
- Find the Parameter under the available parameter and add it by selecting it and clicking the ">>" button
- Click OK
- If satisfied with the connection string click OK
using System.Windows.Forms;
using fyiReporting;
using fyiReporting.RDL;
using fyiReporting.RdlViewer;
class Program
{
[STAThread]
static void Main()
{
System.Windows.Forms.Form frm = new System.Windows.Forms.Form();
frm.Height = 600;
frm.Width = 800;
fyiReporting.RdlViewer.RdlViewer rdlView = new fyiReporting.RdlViewer.RdlViewer();
rdlView.SourceFile = new Uri(@"\path\to\your\report_with_dynamic_connection_string.rdl");
rdlView.Parameters += string.Format("ConnectionString={0}", "The Connection String Goes Here");
rdlView.Rebuild();
rdlView.Dock = DockStyle.Fill;
frm.Controls.Add(rdlView);
Application.Run(frm);
}
}
The first thing that needs to be done is open the report in the designer. In the properties panel make sure "Report" is selected. Find the "Parameters" and click the "..." load button
In the parameter window that opens click "Add". Enter a name. If you want to prompt the user with the builtin prompt enter a prompt. Set the datatype to "String". Click OK.
Back in the main designer go to the menu Data -> Data Sources
Select the data source whose connection should be set by the parameter. Either clear out the connection string and type in the parameter. Or you can Click the "fx" button.
If you clicked the "fx" button clear the connection string, and find the Parameter under the available parameter and add it by selecting it and clicking the ">>" button. Click OK.
If satisfied with the connection string click OK.
The next two screenshot shows a (sample application)[https://github.com/majorsilence/My-FyiReporting/tree/master/Examples/SampleApp] that lets the user enter the connection string.
The first screenshot shows connecting to the sqlitetestdb2.db database and its data.
The second screenshot shows the same report connecting to the northwindEF.db and shows that it has different data.