Skip to main content

DataConnectionBase.Open() Method

Opens the data connection session.

Namespace: DevExpress.DataAccess

Assembly: DevExpress.DataAccess.v24.1.dll

NuGet Packages: DevExpress.DataAccess, DevExpress.Win.PivotGrid, DevExpress.Win.TreeMap

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";
        }
See Also