ActiveReports 18 .NET Edition
Developers / Working with Reports / Page/RDLX Report / Bind a Page/RDLX Report to Data / Bind Page/RDLX Report to SQL, OLEDB, and ODBC Data Providers / Bind Page/RDLX Report to Custom Data Providers (Oracle, PostgreSQL, SQLite)
In This Topic
    Bind Page/RDLX Report to Custom Data Providers (Oracle, PostgreSQL, SQLite)
    In This Topic
    Note: When you bind a report to any custom data provider, you need to modify the ActiveReports configuration file. See Configure ActiveReports for more information.

    This topic explains how to connect to the following data providers:

    When working with a custom data provider, you may need to process user credentials to work with the target source. The LocateCredentials event is used for this purpose.

    The event handler receives an argument of the LocateCredentialsEventArgs type, containing related data. The following LocateCredentialsEventArgs properties provide information, specific to this event.

    Oracle Database

    The Oracle database is not a built-in data source and requires an external provider. However, this data source has a built-in support to locate credentials.

    The example below shows what code you should add to the configuration file.

    Copy Code
    <ReportingConfiguration>
        <Extensions>
            <Data>
                 <Extension Name="ORACLE" Type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess" DisplayName="Oracle Provider" />
            </Data>
        </Extensions>
    </ReportingConfiguration>
    
    Note: To use the Oracle data, you must install the Oracle.ManagedDataAccess or Oracle.ManagedDataAccess.Core NuGet package.

    Add the following code to connect to the Oracle Database as a new data source.

    Copy Code
    private PageReport LoadReport()
    {
        string path = ""; // Your path to the report
        PageReport report = new PageReport(new FileInfo(path));
        report.Document.LocateCredentials += OnLocateCredentials;
        DataSource dataSource = report.Report.DataSources[0]; // Your data source
        if(dataSource.ConnectionProperties.DataProvider == "ORACLE")
        {
            dataSource.ConnectionProperties.ConnectString = ""; // Your connection string
        }
       
        return report;
    }
    private void OnLocateCredentials(object sender, LocateCredentialsEventArgs args)
    {
        args.Password = ""; // Your password if you need it
        args.UserName = ""; // Your username if you need it
    }
    
    Note: We assume that the report has defined data fields and datasets, which can be done in various ways, e.g., in the Web or Windows Forms Designer.

    See an example of a connection string below.

    Copy Code
    Data Source=[database];User Id=[username];Password=[password];Integrated Security=no;
    

    To handle user credentials, you should subscribe to the LocateCredentials event as follows.

    Copy Code
    report.Document.LocateCredentials += OnLocateCredentials;
    

    You should also add a handler to manage the data.

    Copy Code
    private void OnLocateCredentials(object sender, LocateCredentialsEventArgs args)
    {
        args.Password = ""; // Your password if you need it
        args.UserName = ""; // Your username if you need it
    }
    

    PostgreSQL Database

    The PostgreSQL database is not a built-in data source and requires an external provider. However, this data source has a built-in support to locate credentials.

    The example below shows what code you should add to the configuration file.

    Copy Code
    <ReportingConfiguration>
        <Extensions>
            <Data>
                <Extension Name="POSTGRESQL" Type="Npgsql.NpgsqlFactory, Npgsql" DisplayName="PostgreSQL Provider" />
            </Data>
        </Extensions>
    </ReportingConfiguration>
    
    Note: You must install the Npgsql NuGet package to use the PostgreSQL data.

    Add the following code to connect PostgreSQL as a new data source.

    Copy Code
    private PageReport LoadReport()
    {
        string path = ""; // Your path to the report
        PageReport report = new PageReport(new FileInfo(path));
        report.Document.LocateCredentials += OnLocateCredentials;
       
        DataSource dataSource = report.Report.DataSources[0]; // Your data source
        if(dataSource.ConnectionProperties.DataProvider == "POSTGRESQL")
        {
            dataSource.ConnectionProperties.ConnectString = ""; // Your connection string
        }
        return report;
    }
    private void OnLocateCredentials(object sender, LocateCredentialsEventArgs args)
    {
        args.Password = ""; // Your password if you need it
        args.UserName = ""; // Your username if you need it
    }
    

    Note: We assume that the report has defined data fields and datasets, which can be done in various ways, e.g., in the Web or Windows Forms Designer.

    See an example of a connection string below.

    Copy Code
    Uid=[username];Pwd=[password];Host=[host];Port=[port];Database=[dbName];
    

    The code example illustrates that you are adding a PostgtreSQL data provider as a custom data provider. Subscribing to the LocateCredentials event allows you to handle user credentials.

    SQLite or MS SQLite Database

    The example below shows what code you should add to the configuration file.

    Copy Code
    <ReportingConfiguration>
        <Extensions>
            <Data>
                <Extension Name="SQLITE" Type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" DisplayName="SQLite Provider" />
            </Data>
        </Extensions>
    </ReportingConfiguration>
    

    Note: System.Data.SQLite or System.Data.SQLite.Core NuGet package must be installed for using Sqlite data.

    You can also use MS SQLite. Add the following to the configuration file.

    Copy Code
    <ReportingConfiguration>
        <Extensions>
            <Data>
                <Extension Name="MSSQLITE" Type="Microsoft.Data.Sqlite.SqliteFactory, Microsoft.Data.Sqlite” DisplayName="MS SQLite Provider" />
            </Data>
        </Extensions>
    </ReportingConfiguration>
    
    Note: You must install the Microsoft.Data.Sqlite or Microsoft.Data.Sqlite.Core NuGet packages for using the MS SQLite data.

    Add the following code to connect to SQLite database as a new data source.

    Copy Code
    private PageReport LoadReport()
    {
        string path = ""; // Your path to the report
        PageReport report = new PageReport(new FileInfo(path));
       
        DataSource dataSource = report.Report.DataSources[0]; // Your data source
        if(dataSource.ConnectionProperties.DataProvider == "SQLITE") // Or "MSSQLITE" if you use it
        {
            dataSource.ConnectionProperties.ConnectString = ""; // Your connection string
        }
        return report;
    }
    

    See an example of a connection string below.

    Copy Code
    Data Source=[dbName];Version=3;
    

    Note: We assume that the report has defined data fields and datasets, which can be done in various ways, e.g., in the Web or Windows Forms Designer.