Back to Devexpress

Register SQL Data Connections in ASP.NET MVC Reporting

xtrareports-400207-web-reporting-asp-net-mvc-reporting-end-user-report-designer-in-asp-net-mvc-applications-bind-to-data-register-sql-data-connections.md

latest7.9 KB
Original Source

Register SQL Data Connections in ASP.NET MVC Reporting

  • Feb 07, 2025
  • 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 application startup to register the default connection string provider as shown below.

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

public class Global_asax : System.Web.HttpApplication {
    void Application_Start(object sender, EventArgs e) {
        // ...
        DefaultReportDesignerContainer.RegisterDataSourceWizardConfigFileConnectionStringsProvider();
    } 
    // ...
}
vb
Imports DevExpress.XtraReports.Web.ReportDesigner
Imports System
' ...

Public Class Global_asax
    Inherits System.Web.HttpApplication
    Private Sub Application_Start(sender As Object, e As EventArgs)
        ' ... 
    DefaultReportDesignerContainer.RegisterDataSourceWizardConfigFileConnectionStringsProvider()
    End Sub
    ' ... 
End Class

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.

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

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=[email protected];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

Use a Custom Database Schema

Register Predefined Data Sources (ASP.NET MVC)

Register JSON Data Connections (ASP.NET MVC)