Skip to main content
A newer version of this page is available. .

IConnectionProviderService.LoadConnection(String) Method

Returns a connection specified by a name.

Namespace: DevExpress.DataAccess.Wizard.Services

Assembly: DevExpress.DataAccess.v21.1.dll

NuGet Packages: DevExpress.DataAccess, DevExpress.Win.Design

Declaration

SqlDataConnection LoadConnection(
    string connectionName
)

Parameters

Name Type Description
connectionName String

A connection name.

Returns

Type Description
SqlDataConnection

An SqlDataConnection object.

Remarks

The code snippet below implements a service that connects the data source to the MS SQL Server if the connection name is “MyRuntimeConnection”, and creates a connection to the Microsoft SQL Server database file for any other connection name.

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

class CustomConnectionProviderService : IConnectionProviderService
{
    public SqlDataConnection LoadConnection(string connectionName)
    {
        if (connectionName == "MyRuntimeConnection")
        {
            MsSqlConnectionParameters connectionParameters = new MsSqlConnectionParameters()
            {
                ServerName = "localhost",
                DatabaseName = "NorthWind",
                UserName = null,
                Password = null,
                AuthorizationType = MsSqlAuthorizationType.Windows
            };
            return new SqlDataConnection("MyRuntimeConnection", connectionParameters);
        }
        string connectionString = "XpoProvider=MSSqlServer;Data Source=(LocalDB)\\MSSQLLocalDB;" +
            "AttachDbFilename=|DataDirectory|\\Test.mdf;" +
            "Integrated Security=True;Connect Timeout=30";
        CustomStringConnectionParameters fallbackConnectionParameters =
            new CustomStringConnectionParameters(connectionString);
        return new SqlDataConnection(connectionName, fallbackConnectionParameters);
    }
}

The complete code is available in the sample application.

View Example: How to Create a Report Bound to the SQL Data Source

See Also