Skip to main content
.NET 6.0+

AccessConnectionProvider.GetConnectionString(String) Method

Returns a connection string to the specified Microsoft Access data base using the default credentials.

Namespace: DevExpress.Xpo.DB

Assembly: DevExpress.Xpo.v24.1.dll

NuGet Package: DevExpress.Xpo

Declaration

public static string GetConnectionString(
    string database
)

Parameters

Name Type Description
database String

A string that specifies the path and name of the data base to connect to.

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).

The database parameter specifies the name of the database. If the full path is omitted it is assumed that the database resides in the same folder as the application’s executable file.

This method sets the connection string’s “User ID” field to “Admin” and the password to an empty string.

To open Microsoft Access 2007 databases, use the AccessConnectionProvider.GetConnectionStringACE method.

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 Access database. The AccessConnectionProvider.GetConnectionString method is called to construct a connection string to the database. It’s then assigned to the XpoDefault.ConnectionString property.

When a connection is about to be established to a database, a session object obtains the connection string from the XpoDefault.ConnectionString property (unless another connection string is supplied directly to the session). This is then used to connect to the database.

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

XpoDefault.ConnectionString = AccessConnectionProvider.GetConnectionString(
    @"c:\Data\nwind.mdb");

The following code snippets (auto-collected from DevExpress Examples) contain references to the GetConnectionString(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