Class DataConnectionBase
The base class for all data connection components such as
Inheritance
Inherited Members
Namespace: FastReport.Data
Assembly: FastReport.Base.dll
Syntax
public abstract class DataConnectionBase : DataComponentBase, IDisposable, IFRSerializable, IParent
Examples
This example shows how to add a new MS Access connection to the report.
Report report1;
MsAccessDataConnection conn = new MsAccessDataConnection();
conn.DataSource = @"c:\data.mdb";
report1.Dictionary.Connections.Add(conn);
conn.CreateAllTables();
Constructors
DataConnectionBase()
Initializes a new instance of the DataConnectionBase class with default settings.
Declaration
public DataConnectionBase()
Properties
CanContainProcedures
Gets or sets a value indicates if this connection can contain procedures.
Declaration
public bool CanContainProcedures { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
CommandTimeout
Gets or sets the command timeout, in seconds.
Declaration
public int CommandTimeout { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
ConnectionString
Gets or sets a connection string that contains all connection parameters.
Declaration
public string ConnectionString { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
To modify some parameter of the connection, use respective ConnectionStringBuilder class.
Security note: the connection string may contain a user name/password. This information is stored in a report file. By default, it is crypted using the standard FastReport's password. Since FastReport's source code is available to anyone who paid for it, it may be insecure to use the standard password. For more security, you should use own password. To do this, specify it in the Crypter.DefaultPassword property.
Examples
This example demonstrates how to change a connection string:
OleDbConnectionStringBuilder builder = new OleDbConnectionStringBuilder(oleDbConnection1.ConnectionString);
builder.PersistSecurityInfo = false;
oleDbConnection1.ConnectionString = builder.ToString();
ConnectionStringExpression
Gets or sets an expression that returns a connection string.
Declaration
public string ConnectionStringExpression { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
Use this property to set the connection string dynamically.
The recommended way to do this is to define a report parameter. You can do this in the "Data" window. Once you have defined the parameter, you can use it to pass a value to the connection. Set the ConnectionStringExpression property of the connection object to the report parameter's name (so it will look like [myReportParam]). To pass a value to the report parameter from your application, use the SetParameterValue(String, Object) method.
caution
Once you set value for this property, the ConnectionString property will be ignored when report is run.
DataSet
Gets an internal DataSet object that contains all data tables.
Declaration
public DataSet DataSet { get; }
Property Value
Type | Description |
---|---|
DataSet |
IsSqlBased
Gets or sets a value indicates if this connection is SQL-based.
Declaration
public bool IsSqlBased { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
LoginPrompt
Gets or sets a value indicating whether a login dialog appears immediately before opening a connection.
Declaration
public bool LoginPrompt { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Remarks
Set LoginPrompt to true to provide login dialog when establishing a connection. If this property is false (by default), you should provide login information (user name and password) in the ConnectionString property. Though that property is stored in a crypted form, this may be insecure.
Another way to pass login information to the connection is to use ConnectionStringExpression property that is bound to the report parameter. In that case you supply the entire connection string from your application.
Tables
Gets a collection of data tables in this connection.
Declaration
public TableCollection Tables { get; }
Property Value
Type | Description |
---|---|
TableCollection |
Remarks
To add a table to the connection, you must either create a new TableDataSource and add it to this collection or call the CreateAllTables() method which will add all tables available in the database.
Methods
AddChild(Base)
Declaration
public void AddChild(Base child)
Parameters
Type | Name | Description |
---|---|---|
Base | child |
CanContain(Base)
Declaration
public bool CanContain(Base child)
Parameters
Type | Name | Description |
---|---|---|
Base | child |
Returns
Type | Description |
---|---|
System.Boolean |
Clone()
Clone table. For internal use only.
Declaration
public virtual void Clone()
CreateAllProcedures()
Fills the Tables collection with all procedures available in the database.
Declaration
public virtual void CreateAllProcedures()
CreateAllProceduresAsync(CancellationToken)
Fills the Tables collection with all procedures available in the database.
Declaration
public virtual async Task CreateAllProceduresAsync(CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
System.Threading.CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
CreateAllTables()
Fills the Tables collection with all tables available in the database.
Declaration
public void CreateAllTables()
Remarks
This method does not read the table data; to do this, call the LoadData(ArrayList) method of each table.
CreateAllTables(Boolean)
Fills the Tables collection with all tables available in the database.
Declaration
public virtual void CreateAllTables(bool initSchema)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | initSchema | Set to true to initialize each table's schema. |
CreateAllTablesAsync(Boolean, CancellationToken)
Fills the Tables collection with all tables available in the database.
Declaration
public virtual async Task CreateAllTablesAsync(bool initSchema, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | initSchema | Set to true to initialize each table's schema. |
System.Threading.CancellationToken | cancellationToken | Cancellation Token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
CreateAllTablesAsync(CancellationToken)
Fills the Tables collection with all tables available in the database.
Declaration
public Task CreateAllTablesAsync(CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
System.Threading.CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Remarks
This method does not read the table data; to do this, call the LoadDataAsync(ArrayList, CancellationToken) method of each table.
CreateDataSet()
Initializes a DataSet instance.
Declaration
protected virtual DataSet CreateDataSet()
Returns
Type | Description |
---|---|
DataSet | The DataSet object. |
Remarks
This method is used to support FastReport infrastructure. You don't need to use it.
CreateDataSetAsync(CancellationToken)
Initializes a DataSet instance.
Declaration
protected virtual Task<DataSet> CreateDataSetAsync(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<DataSet> | The DataSet object. |
Remarks
This method is used to support FastReport infrastructure. You don't need to use it.
CreateProcedure(String)
Create the stored procedure.
Declaration
public virtual TableDataSource CreateProcedure(string tableName)
Parameters
Type | Name | Description |
---|---|---|
System.String | tableName |
Returns
Type | Description |
---|---|
TableDataSource |
CreateProcedureAsync(String, CancellationToken)
Create the stored procedure.
Declaration
public virtual async Task<TableDataSource> CreateProcedureAsync(string tableName, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
System.String | tableName | |
System.Threading.CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<TableDataSource> |
CreateRelations()
Creates the relations between tables. Applies to XmlDataConnection only.
Declaration
public virtual void CreateRelations()
CreateTable(TableDataSource)
Creates table. For internal use only.
Declaration
public virtual void CreateTable(TableDataSource source)
Parameters
Type | Name | Description |
---|---|---|
TableDataSource | source |
CreateTableAsync(TableDataSource, CancellationToken)
Creates table asynchronously. For internal use only.
Declaration
public virtual async Task CreateTableAsync(TableDataSource source, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
TableDataSource | source | |
System.Threading.CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
CreateUniqueNames(DataConnectionBase)
Declaration
protected void CreateUniqueNames(DataConnectionBase copyTo)
Parameters
Type | Name | Description |
---|---|---|
DataConnectionBase | copyTo |
DeleteTable(TableDataSource)
Deletes table. For internal use only.
Declaration
public virtual void DeleteTable(TableDataSource source)
Parameters
Type | Name | Description |
---|---|---|
TableDataSource | source |
Dispose(Boolean)
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing |
Overrides
DisposeConnection(DbConnection)
Disposes a connection.
Declaration
public virtual void DisposeConnection(DbConnection connection)
Parameters
Type | Name | Description |
---|---|---|
DbConnection | connection | The connection to dispose. |
DisposeConnectionAsync(DbConnection)
Disposes a connection.
Declaration
public virtual async Task DisposeConnectionAsync(DbConnection connection)
Parameters
Type | Name | Description |
---|---|---|
DbConnection | connection | The connection to dispose. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
DisposeDataSet()
Disposes a DataSet.
Declaration
protected void DisposeDataSet()
Remarks
This method is used to support FastReport infrastructure. You don't need to use it.
FillTableData(DataTable, String, CommandParameterCollection)
Fills the table data.
Declaration
public virtual void FillTableData(DataTable table, string selectCommand, CommandParameterCollection parameters)
Parameters
Type | Name | Description |
---|---|---|
DataTable | table | DataTable to fill. |
System.String | selectCommand | The SQL select command. |
CommandParameterCollection | parameters | SQL parameters. |
Remarks
Usually you don't need to use this method. Internally it uses the GetConnection() and GetAdapter(String, DbConnection, CommandParameterCollection) methods to fill the table data. If you create own connection component that does not use nor connection or adapter, then you need to override this method.
FillTableDataAsync(DataTable, String, CommandParameterCollection, CancellationToken)
Fills the table data.
Declaration
public virtual async Task FillTableDataAsync(DataTable table, string selectCommand, CommandParameterCollection parameters, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
DataTable | table | DataTable to fill. |
System.String | selectCommand | The SQL select command. |
CommandParameterCollection | parameters | SQL parameters. |
System.Threading.CancellationToken | cancellationToken | Cancellation Token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Remarks
Usually you don't need to use this method. Internally it uses the GetConnection() and GetAdapter(String, DbConnection, CommandParameterCollection) methods to fill the table data. If you create own connection component that does not use nor connection or adapter, then you need to override this method.
FillTableSchema(DataTable, String, CommandParameterCollection)
Fills the table schema.
Declaration
public virtual void FillTableSchema(DataTable table, string selectCommand, CommandParameterCollection parameters)
Parameters
Type | Name | Description |
---|---|---|
DataTable | table | DataTable to fill. |
System.String | selectCommand | The SQL select command. |
CommandParameterCollection | parameters | SQL parameters. |
Remarks
Usually you don't need to use this method. Internally it uses the GetConnection() and GetAdapter(String, DbConnection, CommandParameterCollection) methods to fill the table schema. If you create own connection component that does not use nor connection or adapter, then you need to override this method.
FillTableSchemaAsync(DataTable, String, CommandParameterCollection, CancellationToken)
Fills the table schema.
Declaration
public virtual async Task FillTableSchemaAsync(DataTable table, string selectCommand, CommandParameterCollection parameters, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
DataTable | table | DataTable to fill. |
System.String | selectCommand | The SQL select command. |
CommandParameterCollection | parameters | SQL parameters. |
System.Threading.CancellationToken | cancellationToken | Cancellation Token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Remarks
Usually you don't need to use this method. Internally it uses the GetConnection() and GetAdapter(String, DbConnection, CommandParameterCollection) methods to fill the table schema. If you create own connection component that does not use nor connection or adapter, then you need to override this method.
FindTableDataSource(DataTable)
Declaration
protected TableDataSource FindTableDataSource(DataTable table)
Parameters
Type | Name | Description |
---|---|---|
DataTable | table |
Returns
Type | Description |
---|---|
TableDataSource |
GetAdapter(String, DbConnection, CommandParameterCollection)
Returns a
Declaration
public virtual DbDataAdapter GetAdapter(string selectCommand, DbConnection connection, CommandParameterCollection parameters)
Parameters
Type | Name | Description |
---|---|---|
System.String | selectCommand | The SQL command used to fetch a table data rows. |
DbConnection | connection | The connection object. |
CommandParameterCollection | parameters | The select command parameters. |
Returns
Type | Description |
---|---|
DbDataAdapter | The DbDataAdapter object. |
Remarks
You should override this method if you are developing a new connection component. In this method, you need to create the adapter and set its SelectCommand's parameters.
If your connection does not use data adapter, you need to override the FillTableSchema(DataTable, String, CommandParameterCollection) and FillTableData(DataTable, String, CommandParameterCollection) methods instead.
Examples
Here is the example of this method implementation:
public override DbDataAdapter GetAdapter(string selectCommand, DbConnection connection,
CommandParameterCollection parameters)
{
OleDbDataAdapter adapter = new OleDbDataAdapter(selectCommand, connection as OleDbConnection);
foreach (CommandParameter p in parameters)
{
OleDbParameter parameter = adapter.SelectCommand.Parameters.Add(p.Name, (OleDbType)p.DataType, p.Size);
parameter.Value = p.Value;
}
return adapter;
}
GetChildObjects(ObjectCollection)
Declaration
public void GetChildObjects(ObjectCollection list)
Parameters
Type | Name | Description |
---|---|---|
ObjectCollection | list |
GetChildOrder(Base)
Declaration
public int GetChildOrder(Base child)
Parameters
Type | Name | Description |
---|---|---|
Base | child |
Returns
Type | Description |
---|---|
System.Int32 |
GetConnection()
Returns a connection object.
Declaration
public virtual DbConnection GetConnection()
Returns
Type | Description |
---|---|
DbConnection | The DbConnection instance. |
Remarks
Either creates a new DbConnection instance of type provided by the GetConnectionType() method, or returns the application connection if set in the Config.DesignerSettings.ApplicationConnection.
GetConnectionStringWithLoginInfo(String, String)
Gets a connection string that contains username and password specified.
Declaration
protected virtual string GetConnectionStringWithLoginInfo(string userName, string password)
Parameters
Type | Name | Description |
---|---|---|
System.String | userName | User name. |
System.String | password | Password. |
Returns
Type | Description |
---|---|
System.String |
Remarks
Override this method to pass login information to the connection. Typical implementation must get the existing ConnectionString, merge specified login information into it and return the new value.
GetConnectionType()
Returns a type of connection.
Declaration
public virtual Type GetConnectionType()
Returns
Type | Description |
---|---|
System.Type | Type instance. |
Remarks
You should override this method if you developing a new connection component.
If your connection component does not use data connection, you need to override the FillTableSchema(DataTable, String, CommandParameterCollection) and FillTableData(DataTable, String, CommandParameterCollection) methods instead.
Examples
Here is the example of this method implementation:
public override Type GetConnectionType()
{
return typeof(OleDbConnection);
}
GetDataSetAsync(CancellationToken)
Declaration
public async Task<DataSet> GetDataSetAsync(CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
System.Threading.CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<DataSet> |
GetExpressions()
Declaration
public override string[] GetExpressions()
Returns
Type | Description |
---|---|
System.String[] |
Overrides
GetParameterType()
Gets the type of parameter that is specific to this connection.
Declaration
public virtual Type GetParameterType()
Returns
Type | Description |
---|---|
System.Type | The parameter's type. |
Remarks
This property is used in the report designer to display available data types when you edit the connection parameters. For example, the type of OleDbConnection parameter is a OleDbType.
GetProcedureNames()
Gets an array of subroutine names available in the database.
Declaration
public virtual string[] GetProcedureNames()
Returns
Type | Description |
---|---|
System.String[] | An array of strings. |
GetProcedureNamesAsync(CancellationToken)
Gets an array of subroutine names available in the database.
Declaration
public virtual async Task<string[]> GetProcedureNamesAsync(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.String[]> | An array of strings. |
GetSchema(String)
Declaration
protected DataTable GetSchema(string collectionName)
Parameters
Type | Name | Description |
---|---|---|
System.String | collectionName |
Returns
Type | Description |
---|---|
DataTable |
GetSchema(String, String[])
Declaration
protected DataTable GetSchema(string collectionName, string[] restrictionValues)
Parameters
Type | Name | Description |
---|---|---|
System.String | collectionName | |
System.String[] | restrictionValues |
Returns
Type | Description |
---|---|
DataTable |
GetSchemaAsync(String, String[], CancellationToken)
Declaration
protected async Task<DataTable> GetSchemaAsync(string collectionName, string[] restrictionValues, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
System.String | collectionName | |
System.String[] | restrictionValues | |
System.Threading.CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<DataTable> |
GetSchemaAsync(String, CancellationToken)
Declaration
protected async Task<DataTable> GetSchemaAsync(string collectionName, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
System.String | collectionName | |
System.Threading.CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<DataTable> |
GetTableNames()
Gets an array of table names available in the database.
Declaration
public virtual string[] GetTableNames()
Returns
Type | Description |
---|---|
System.String[] | An array of strings. |
GetTableNamesAsync(CancellationToken)
Gets an array of table names available in the database.
Declaration
public virtual async Task<string[]> GetTableNamesAsync(CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
System.Threading.CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.String[]> | An array of strings. |
OpenConnection(DbConnection)
Opens a specified connection object.
Declaration
public virtual void OpenConnection(DbConnection connection)
Parameters
Type | Name | Description |
---|---|---|
DbConnection | connection | Connection to open. |
Remarks
Use this method to open a connection returned by the GetConnection() method.
This method displays a login dialog if your connection has the LoginPrompt property set to true. Once you have entered an user name and password in this dialog, it will remeber the entered values and will not used anymore in this report session.
OpenConnectionAsync(DbConnection, CancellationToken)
Opens a specified connection object.
Declaration
public virtual async Task OpenConnectionAsync(DbConnection connection, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
DbConnection | connection | Connection to open. |
System.Threading.CancellationToken | cancellationToken | Cancellation Token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Remarks
Use this method to open a connection returned by the GetConnection() method.
This method displays a login dialog if your connection has the LoginPrompt property set to true. Once you have entered an user name and password in this dialog, it will remeber the entered values and will not used anymore in this report session.
PrepareSelectCommand(String, String, DbConnection)
Declaration
protected string PrepareSelectCommand(string selectCommand, string tableName, DbConnection connection)
Parameters
Type | Name | Description |
---|---|---|
System.String | selectCommand | |
System.String | tableName | |
DbConnection | connection |
Returns
Type | Description |
---|---|
System.String |
QuoteIdentifier(String, DbConnection)
Quotes the specified DB identifier such as table name or column name.
Declaration
public abstract string QuoteIdentifier(string value, DbConnection connection)
Parameters
Type | Name | Description |
---|---|---|
System.String | value | Identifier to quote. |
DbConnection | connection | The opened DB connection. |
Returns
Type | Description |
---|---|
System.String | The quoted identifier. |
RemoveChild(Base)
Declaration
public void RemoveChild(Base child)
Parameters
Type | Name | Description |
---|---|---|
Base | child |
Serialize(FRWriter)
Declaration
public override void Serialize(FRWriter writer)
Parameters
Type | Name | Description |
---|---|---|
FRWriter | writer |
Overrides
SetChildOrder(Base, Int32)
Declaration
public void SetChildOrder(Base child, int order)
Parameters
Type | Name | Description |
---|---|---|
Base | child | |
System.Int32 | order |
SetConnectionString(String)
Sets the connection string.
Declaration
protected virtual void SetConnectionString(string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | value | New connection string. |
Remarks
Use this method if you need to perform some actions when the connection string is set.
UpdateLayout(Single, Single)
Declaration
public void UpdateLayout(float dx, float dy)
Parameters
Type | Name | Description |
---|---|---|
System.Single | dx | |
System.Single | dy |