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, 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)
Adds a child object to this object's childs.
Declaration
public void AddChild(Base child)
Parameters
Type | Name | Description |
---|---|---|
Base | child | Object to add. |
CanContain(Base)
Gets a value indicating that this object can contain the specified child object.
Declaration
public bool CanContain(Base child)
Parameters
Type | Name | Description |
---|---|---|
Base | child | Child object. |
Returns
Type | Description |
---|---|
System.Boolean | true if this object can contain the specified child object; otherwise, false. |
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()
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. |
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.
CreateProcedure(String)
Create the stored procedure.
Declaration
public virtual TableDataSource CreateProcedure(string tableName)
Parameters
Type | Name | Description |
---|---|---|
System.String | tableName |
Returns
Type | Description |
---|---|
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 |
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. |
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.
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.
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)
Gets a list of child objects.
Declaration
public void GetChildObjects(ObjectCollection list)
Parameters
Type | Name | Description |
---|---|---|
ObjectCollection | list | List to fill with values. |
GetChildOrder(Base)
Returns z-order of the specified child object.
Declaration
public int GetChildOrder(Base child)
Parameters
Type | Name | Description |
---|---|---|
Base | child | Child object. |
Returns
Type | Description |
---|---|
System.Int32 | Z-order of the specified object. |
Remarks
This method must return the index of a specified child object in the internal child list.
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);
}
GetExpressions()
Gets all expressions contained in the object.
Declaration
public override string[] GetExpressions()
Returns
Type | Description |
---|---|
System.String[] | Array of expressions or null if object contains no expressions. |
Overrides
Remarks
Do not call this method directly. You may override it if you are developing a new component for FastReport.
This method is called by FastReport each time before run a report. FastReport do this to collect all expressions and compile them. For example, GetExpressions method of the TextObject class parses the text and returns all expressions found in the text.
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 table names available in the database.
Declaration
public virtual string[] GetProcedureNames()
Returns
Type | Description |
---|---|
System.String[] | An array of strings. |
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. |
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.
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)
Removes a specified object from this object's childs.
Declaration
public void RemoveChild(Base child)
Parameters
Type | Name | Description |
---|---|---|
Base | child |
Serialize(FRWriter)
Serializes the object.
Declaration
public override void Serialize(FRWriter writer)
Parameters
Type | Name | Description |
---|---|---|
FRWriter | writer | Writer object. |
Overrides
Remarks
Do not call this method directly. You should override it if you are developing a new component for FastReport.
This method is called when the object needs to save the state. It may happen when:
- saving the report to the file or stream;
- saving the report to the designer's undo buffer;
- assigning the object to another object using the Assign(Base) or AssignAll methods;
- saving the object to the designer's clipboard;
- saving the object to the preview (when run a report).
SetChildOrder(Base, Int32)
Sets the z-order of the specified object.
Declaration
public void SetChildOrder(Base child, int order)
Parameters
Type | Name | Description |
---|---|---|
Base | child | Child object. |
System.Int32 | order | New Z-order. |
Remarks
This method must place the specified child object at the specified position in the internal child list.
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)
Updates the children layout when the size of this object is changed by dx, dy values.
Declaration
public void UpdateLayout(float dx, float dy)
Parameters
Type | Name | Description |
---|---|---|
System.Single | dx | X delta. |
System.Single | dy | Y delta. |
Remarks
This method must update positions/sizes of child objects whose Dock or Anchor properties are set to non-default values.