Skip to main content
.NET 6.0+

MSSqlConnectionProvider.GetConnectionString(String, String) Method

Returns a connection string used to open a specified Microsoft SQL database using Windows Integrated Security.

Namespace: DevExpress.Xpo.DB

Assembly: DevExpress.Xpo.v23.2.dll

NuGet Package: DevExpress.Xpo

Declaration

public static string GetConnectionString(
    string server,
    string database
)

Parameters

Name Type Description
server String

A string that specifies the SQL server name.

database String

A string that specifies the database name.

Returns

Type Description
String

A connection string.

Remarks

The value returned by this method can be used to initialize a Session’s connection string (for instance, via the Session.ConnectionString or XpoDefault.ConnectionString property).

Note

The string returned by the GetConnectionString method contains an extra parameter that identifies the database type to which a connection should be established, so it’s not fully compatible with the standard connection string format. When a Session receives this connection string, it removes this extra parameter and then passes the valid connection string to the database.

Example

The following code demonstrates how to connect to an Microsoft SQL database. The MSSqlConnectionProvider.GetConnectionString method is called to construct a connection string to the database. It is then assigned to the default session via the Session.ConnectionString property.

using DevExpress.Xpo;
using DevExpress.Xpo.DB;

Session.DefaultSession.ConnectionString = MSSqlConnectionProvider.GetConnectionString(
    "SERVER", "sa", "", "Northwind");

The following code snippets (auto-collected from DevExpress Examples) contain references to the GetConnectionString(String, String) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also