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

DataConnectionBase.Open() Method

Opens the data connection session.

Namespace: DevExpress.DataAccess

Assembly: DevExpress.DataAccess.v18.2.dll

Declaration

public void Open()

Example

In this example, the TableQuery.GetSql method is used to obtain the query string that is used to fetch data from the connected data source.

Prior to using this method, open the corresponding data connection by calling the DataConnectionBase.Open method of the SqlDataConnection class.

using System;
using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.Sql;
using DevExpress.XtraReports.UI;
// ...
        private void XtraReport1_DataSourceDemanded(object sender, EventArgs e) {
            // Create a new SQL data source and specify its connection parameters.
            var sqlDataSource = new SqlDataSource(new Access97ConnectionParameters() {
                FileName = @"..//..//nwind.mdb"
            });

            // Create a query and assign it to the data source.
            SelectQuery query = SelectQueryFluentBuilder
                .AddTable("Categories")
                .SelectColumns("CategoryID", "CategoryName")
                .Build("MyQuery");
            sqlDataSource.Queries.Add(query);

            // Open the connection to the data source.
            sqlDataSource.Connection.Open();

            // Obtain the database schema of the connected data source.
            var sql = query.GetSql(sqlDataSource.Connection.GetDBSchema());

            // Assign the data source to the report.
            this.DataSource = sqlDataSource;
            this.DataMember = "MyQuery";
        }

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