Skip to main content

IConnectionProviderService.LoadConnection(String) Method

Loads the specified SqlDataConnection.

Namespace: DevExpress.DataAccess.Wizard.Services

Assembly: DevExpress.DataAccess.v23.2.dll

NuGet Packages: DevExpress.DataAccess, DevExpress.Win.PivotGrid, DevExpress.Win.TreeMap

Declaration

SqlDataConnection LoadConnection(
    string connectionName
)

Parameters

Name Type Description
connectionName String

A String value, specifying the connection name.

Returns

Type Description
SqlDataConnection

An SqlDataConnection object.

Remarks

The following code shows how to implement the IConnectionProviderService interface:

using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.Sql;
using DevExpress.DataAccess.Wizard.Services;
// ...

public class CustomConnectionProviderService : IConnectionProviderService {
    public SqlDataConnection LoadConnection(string connectionName) {
        // Specify custom connection parameters.
        return new SqlDataConnection(connectionName, 
            new MsSqlConnectionParameters("localhost", "dataBaseName", "userName", "password", MsSqlAuthorizationType.Windows));
    }
}

The IConnectionProviderService.LoadConnection method is invoked for each connection that is serialized in the report definition file. Use the connectionName parameter to specify connection options and return an SqlDataConnection object.

Use the implemented interface in an application that invokes a report‘s Print Preview or End-User Report Designer:

  • Windows Forms

    The following code adds a custom connection provider service to the report’s PrintingSystem and displays the Print Preview:

    using DevExpress.DataAccess.Wizard.Services;
    using DevExpress.XtraReports.UI;
    
    // ...
    
    XtraReport report = new XtraReport();
    report.LoadLayout("XtraReport1.repx");
    (report as IServiceContainer).AddService(typeof(IConnectionProviderService), new CustomConnectionProviderService());
    ReportPrintTool pt = new ReportPrintTool(report);
    pt.ShowPreviewDialog();
    

    The following code invokes the implemented IConnectionProviderService interface in the End-User Report Designer‘s DesignPanelLoaded event handler and launches the End-User Report Designer:

    using DevExpress.DataAccess.Wizard.Services;
    using DevExpress.XtraReports.UI;
    
    // ...
    
    XtraReport report = new XtraReport();
    report.LoadLayout("XtraReport1.repx");
    ReportDesignTool tool = new ReportDesignTool(report);
    tool.DesignRibbonForm.DesignMdiController.DesignPanelLoaded += DesignMdiController_DesignPanelLoaded;
    tool.ShowRibbonDesignerDialog();
    
    private void ReplaceService(IServiceContainer container, Type serviceType, object serviceInstance) {
        if (container.GetService(serviceType) != null)
            container.RemoveService(serviceType);
        container.AddService(serviceType, serviceInstance);
    }
    private void DesignMdiController_DesignPanelLoaded(object sender, DevExpress.XtraReports.UserDesigner.DesignerLoadedEventArgs e) {
        ReplaceService(e.DesignerHost, typeof(IConnectionProviderService), new CustomConnectionProviderService());
    }
    
  • WPF

    The following code adds a custom connection provider service to the report’s PrintingSystem and displays the Document Preview:

    using DevExpress.DataAccess.Wizard.Services;
    using DevExpress.XtraReports.UI;
    
    // ...
    
    XtraReport report = new XtraReport();
    report.LoadLayout("XtraReport1.repx");
    report.PrintingSystem.AddService(typeof(IConnectionProviderService), new CustomConnectionProviderService());  
    documentPreviewControl.DocumentSource = report;
    report.CreateDocument();
    

    The following code registers the implemented IConnectionProviderService interface and launches the End-User Report Designer:

    <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:dxrud="http://schemas.devexpress.com/winfx/2008/xaml/reports/userdesigner" x:Class="TestDesigner.MainWindow"
            Title="MainWindow" Height="350" Width="525">
        <dxrud:ReportDesigner Name="ReportDesigner">
            <dxrud:ReportDesigner.ServicesRegistry>
                <dxda:TypeEntry ServiceType="{x:Type dxdaw:IConnectionStorageService}" ConcreteType="{x:Type local:ConnectionStorageService}" />
                <dxda:TypeEntry ServiceType="{x:Type dxdaw:IConnectionProviderService}" ConcreteType="{x:Type local:ConnectionProviderService}" />
            </dxrud:ReportDesigner.ServicesRegistry>
        </dxrud:ReportDesigner>
    </Window>
    
  • Web Report Viewer and Designer

    See the IDataSourceWizardConnectionStringsProvider interface description for instructions on how to store data connections.

See Also