Back to Devexpress

MSSqlConnectionProvider.GetConnectionString(String, String, String, String) Method

xpo-devexpress-dot-xpo-dot-db-dot-mssqlconnectionprovider-dot-getconnectionstring-x28-system-dot-string-system-dot-string-system-dot-string-system-dot-string-x29.md

latest3.6 KB
Original Source

MSSqlConnectionProvider.GetConnectionString(String, String, String, String) Method

Returns a connection string used to open a specified Microsoft SQL database using provided login credentials.

Namespace : DevExpress.Xpo.DB

Assembly : DevExpress.Xpo.v25.2.dll

NuGet Package : DevExpress.Xpo

Declaration

csharp
public static string GetConnectionString(
    string server,
    string userId,
    string password,
    string database
)
vb
Public Shared Function GetConnectionString(
    server As String,
    userId As String,
    password As String,
    database As String
) As String

Parameters

NameTypeDescription
serverString

A string that specifies the SQL server’s name.

| | userId | String |

A string that specifies a user name.

| | password | String |

A string that specifies a password.

| | database | String |

A string that specifies the database name.

|

Returns

TypeDescription
String

A connection string.

|

Remarks

You can use this method’s return value to initialize a Session’s connection string (for instance, via the Session.ConnectionString or XpoDefault.ConnectionString property).

Note

The GetConnectionString method’s return value 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.

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

Session.DefaultSession.ConnectionString = MSSqlConnectionProvider.GetConnectionString(
    "SERVER", "sa", "", "Northwind");
vb
Imports DevExpress.Xpo
Imports DevExpress.Xpo.DB

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

See Also

Session.ConnectionString

XpoDefault.ConnectionString

MSSqlConnectionProvider Class

MSSqlConnectionProvider Members

DevExpress.Xpo.DB Namespace