Customize Data Connections in the Data Source Wizard (WinForms)
- 2 minutes to read
This topic describes how you can specify data connections displayed in the list of available connections when the user adds a new data source.
Implement a Connection Storage
When a user adds a new data source, the list of available connections in the Data Source Wizard is populated with connections defined in the application configuration file.
You can use a custom storage to load and save the Data Source Wizard connections. For this, create a class that implements the IConnectionStorageService interface. The GetConnections method should return a collection of all available connections. You can decide in code whether to include connections defined in the application configuration file. The SaveConnection method should save connection information to a storage (the connectons.xml
file in this example).
Important
In this example, the connection string in the XML file is not encrypted and exposes sensitive information (a username and a password). You should protect the file storage to prevent unauthorized access in a real-world application.
Hide Connection Parameters in Saved Reports
When a user saves a report in the Report Designer, the resulting file contains complete connection information, including username and password. For security reasons, you may wish to hide connection parameters from users and not save sensitive information in report files, so that the REPX file contains only the connection name.
To apply security restrictions, create a connection storage for the End-User Report Designer and register a service that resolves a connection name to a valid connection string when the user loads a report for preview, print, or export.
Do the following:
- Create a service that implements the IConnectionStorageService, as described in the previous section of this help topic.
- Enable the StoreConnectionNameOnly option in the IConnectionStorageService.SaveConnection method.
- Disable the SqlWizardSettings.DisableNewConnections option to prevent users from creating new connections.
- Create a service that implements the IConnectionProviderService interface. The service allows users to open a saved report with a data source whose connection is specified by name, and view, print, and export that report.
The sample code is shown in the following example: