Implements data-aware operations for working with an MS SQL Server or MS SQL Azure database.
The MSSqlConnectionProvider class implements data-aware operations for working with MS SQL databases. In most cases, there is no need to create connection providers explicitly, as they are created automatically by a Session object based upon a connection string.
To connect to a specific MS SQL database, you can generate a connection string via the static MSSqlConnectionProvider.GetConnectionString method. This connection string will contain information on the provider (MSSqlConnectionProvider) that will be used to work with the database. Supply this connection string to a Session object (for instance, via the Session.ConnectionString or XpoDefault.ConnectionString property). When a connection to a database is to be established, the session will create a corresponding connection provider based upon the connection string and then perform all data-aware operations using this connection provider.
There are also cases when you need to create a connection provider explicitly via its constructor, for instance:
- When sharing a single IDataLayer object between multiple sessions, a connection provider should be passed to the data layer’s constructor. See the IDataLayer topic for additional information.
- When manually maintaining a connection pool.
The following code demonstrates how to connect to an MS 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");
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the MSSqlConnectionProvider class.
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.