Create a Data Source with the .NET API

The following is a quick explanation for how to create a Data Source using the .NET Api.

Introduction

First, ensure that your application is referencing the DataSource class, which is located in the WebReports.Api.Data namespace.

using WebReports.Api.Data;

Example

/* Manually Creating a Data Source */

DataSource myDataSource = new DataSource(myApi.PageInfo);

myDataSource.Name = "Northwind";
myDataSource.DbType = "mssql";
myDataSource.Schema = "dbo";
myDataSource.DataConnStr = "Server=DBSERVER;Database=Northwind;uid=admin;pwd=pass;";

Breakdown

NOTE: Data Sources created in the API are unique to their session.

First, create a new Data Source using the following overloaded constructor:

new DataSource(myApi.PageInfo);

The DataSource constructor requires the Api's PageInfo object as the first argument.

Give the data source a name which will appear in the report designer:

myDataSource.Name = "Northwind";

Or you can retrieve an existing Data Source from the current configuration:

myApi.DataSources.GetDataSource("Northwind");

This method requires the string "Name" of the Data Source as an argument.

Then set the database type:

myDataSource.DbType = "mssql";

This field accepts the following valid database types as strings:

NOTE: Ensure that you have the correct drivers for the database type.

Finally, set the connection string:

myDataSource.DataConnStr = "Server=DBSERVER;Database=Northwind;uid=admin;pwd=pass;";

For more information on database connection strings, see ConnectionStrings.com. (This is a third party resource, unaffiliated with Exago Inc).

If necessary, you can set the schema/owner name (if left blank, it will use the default):

myDataSource.Schema = "dbo";