Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

Register SQL Data Connections in ASP.NET Web Forms Reporting

  • 6 minutes to read

This document describes how to provide a set of SQL data connections to the Web Report Designer. The Data Source Wizard displays these connections when end users create new SQL data sources.

#Use a Project’s Connection Strings

You can enable the Report Designer to use connection strings that you specified in the application’s configuration file (Web.config).

Call the static DefaultReportDesignerContainer.RegisterDataSourceWizardConfigFileConnectionStringsProvider method at the application’s startup to register the default connection string provider as shown below.

using DevExpress.XtraReports.Web.ReportDesigner;
using System;
// ...

public class Global_asax : System.Web.HttpApplication {
    void Application_Start(object sender, EventArgs e) {
        // ...
        DefaultReportDesignerContainer.RegisterDataSourceWizardConfigFileConnectionStringsProvider();
    } 
    // ...
}

Important

When the Data Source wizard obtains connection strings from the Web.config file, only the connection names are serialized with the report definition.

#Implement a Custom Connection Strings Provider

This approach allows you to define data connections to display in the Data Source Wizard when end users configure a report’s data source.

  1. Implement the IDataSourceWizardConnectionStringsProvider interface as demonstrated below to create a custom connection string provider.

    using DevExpress.DataAccess.ConnectionParameters;
    using DevExpress.DataAccess.Native;
    using DevExpress.DataAccess.Web;
    using System.Collections.Generic;
    // ...
    
    public class MyDataSourceWizardConnectionStringsProvider : IDataSourceWizardConnectionStringsProvider {
        public Dictionary<string, string> GetConnectionDescriptions() {
            Dictionary<string, string> connections = AppConfigHelper.GetConnections().Keys.ToDictionary(x => x, x => x);
    
            // Customize the loaded connections list. 
            connections.Remove("LocalSqlServer");
            connections.Add("CustomDbConnection", "Custom DB Connection");
            connections.Add("CustomSqlConnection", "Custom SQL Connection");
            return connections;
        }
    
        public DataConnectionParametersBase GetDataConnectionParameters(string name) {
            // Return custom connection parameters for the custom connection(s). 
            if (name == "CustomDbConnection") {
                return new SQLiteConnectionParameters() {
                    FileName = "nwind.db",
                    Password = null
                };
            }
            else if (name == "CustomSqlConnection") {
                return new MsSqlConnectionParameters("localhost", "dbName", "userName", "password", MsSqlAuthorizationType.SqlServer);
            }
            return AppConfigHelper.LoadConnectionParameters(name);
        }
    }
    

    In this code sample, the IDataSourceWizardConnectionStringsProvider.GetConnectionDescriptions method obtains existing connection strings from the Web.config file, removes an undesired data connection, and adds a new custom connection with a description.

    The IDataSourceWizardConnectionStringsProvider.GetDataConnectionParameters method provides connection parameters for a custom data connection.

  2. Call the static DefaultReportDesignerContainer.RegisterDataSourceWizardConnectionStringsProvider<T> method at the application’s startup to register the custom connection string provider.

    using DevExpress.XtraReports.Web.ReportDesigner;
    using System;
    // ...
    
    public class Global_asax : System.Web.HttpApplication {
        void Application_Start(object sender, EventArgs e) {
            // ...
            // Register the custom connection strings provider.
            DefaultReportDesignerContainer.RegisterDataSourceWizardConnectionStringsProvider<MyDataSourceWizardConnectionStringsProvider>();
        }
        // ...
    }
    

    This method has another overload with the overrideWebConfigConnections parameter. When you call the method without parameters or with the parameter set to false, data connection parameters are serialized with the report data source when the report is passed to the client.

    Note

    The MachineKey algorithm is used to encrypt these parameters. You can implement a custom data protection mechanism using the ISecureDataConverter or IDataSourceProtectionService interface.

    If you pass true as the method parameter, only the connection name is serialized with the report definition (data connection parameters are not saved). When the Web Document Viewer and the Report Designer’s Preview generate a report document, they request connection parameters from the custom connection string provider instead from the predefined provider that gets connection information from the Web.config file.

    using DevExpress.XtraReports.Web.ReportDesigner;
    using System;
    // ...
    
    public class Global_asax : System.Web.HttpApplication {
        void Application_Start(object sender, EventArgs e) {
            // ...
            DefaultReportDesignerContainer.RegisterDataSourceWizardConnectionStringsProvider<MyDataSourceWizardConnectionStringsProvider>(true);
        }
        // ...
    }
    

Note

The IDataSourceWizardConnectionStringsProvider interface allows you to fill the connection string list for the Data Source Wizard only.

If you print or export reports in code outside the Web Report Designer’s context, implement the cross-platform IConnectionProviderService interface instead.

#Connection String Examples

The Data Source Wizard can use only connection strings that contain the XpoProvider used to identify a data source provider. If you don not specify, the “Schema loading failed.” error occurs.

You can use one of the following approaches to avoid this error:

  • Add the XpoProvider key to the existing connection strings.
  • Duplicate the connection strings and add the XpoProvider key to the copied strings. You should also implement a custom connection string provider to display the strings with this key only. See the next document section for implementation details.

See connection string examples in the table below:

Relational Database System

Connection String Sample

Microsoft SQL Server

XpoProvider=MSSqlServer;Data Source=(local);User ID=username;Password=password;Initial Catalog=database;Persist Security Info=true

The MS SQL Server data provider is automatically specified if you set the “Initial Catalog” parameter and do not use the word “Provider” (for instance, the “XpoProvider” parameter) in the connection string.

Microsoft Access

XpoProvider=MSAccess;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;

XpoProvider=MSAccess;Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\mydatabase.accdb;User Id=admin;Password=;

Microsoft SQL Server CE

XpoProvider=MSSqlServerCE;Data Source=MyDatabase.sdf;Password=MyPassword

Oracle Database

XpoProvider=Oracle;Data Source=TORCL;User ID=MyUserName;Password=MyPassword

XpoProvider=ODP;Data Source=TORCL;User ID=MyUserName;Password=MyPassword

XpoProvider=ODPManaged;Data Source=TORCL;User ID=MyUserName;Password=MyPassword

Amazon Redshift

XpoProvider=Amazon Redshift;Server=127.0.0.1;User ID=MyUserName;Password=MyPassword;Database=MyDatabase;Encoding=UNICODE

Google BigQuery

XpoProvider=BigQuery;ProjectID=myProject;DataSetId=myDataSet;OAuthClientId=myClientId;OAuthClientSecret=mySecret;OAuthRefreshToken=myRefreshToken

XpoProvider=BigQuery;ProjectId=project;DatasetId=dataset;ServiceAccountEmail=example@gmail.com;PrivateKeyFileName=key.p12

Teradata

XpoProvider=Teradata;Data Source=myServerAddress;User ID=myUsername;Password=myPassword;

SAP HANA

XpoProvider=Hana;server=myServerAddress:40000;uid=user;pwd=password;

SAP Sybase Advantage

XpoProvider=Advantage;Data Source=\myserver\myvolume\mypat\mydd.add;ServerType=local;User ID=ASSSYS;TrimTrailingSpaces=true

SAP Sybase ASE

XpoProvider=Ase;Port=5000;Data Source=MyAseServer;User ID=MyUserName;Password=MyPassword;Initial Catalog=MyDatabase;Persist Security Info=true

SAP SQL Anywhere

XpoProvider=Asa;eng=server;uid=user;pwd=password;dbn=database;persist security info=true;

IBM DB2

XpoProvider=DB2;Server=server:port;Database=database;UID=user;PWD=password;

Firebird

XpoProvider=Firebird;DataSource=localhost;User=SYSDBA;Password=masterkey;Database=MyDatabase.fdb;ServerType=0;Charset=NONE

MySQL

XpoProvider=MySql;Server=MyServerAddress;User ID=MyUserName;Password=MyPassword;Database=MyDatabase;Persist Security Info= true;Charset=utf8

Pervasive PSQL

XpoProvider=Pervasive;Server=MyServerAddress;UID=MyUserName;PWD=MyPassword;ServerDSN=MyDatabase

PostgreSQL

XpoProvider=Postgres;Server=127.0.0.1;User ID=MyUserName;Password=MyPassword;Database=MyDatabase;Encoding=UNICODE

VistaDB

XpoProvider=VistaDB;Data Source=C:\mydatabase.vdb4

XpoProvider=VistaDB5;Data Source=C:\mydatabase.vdb5

SQLite

XpoProvider=SQLite;Data Source=filename

XML file

XpoProvider=InMemoryDataStore;data source=D:\Contacts.xml;read only=True

Note

The connection strings demonstrated above are examples. You can specify alternative variants.

See Also