TdxBackendDatabaseSQLConnection.ConnectionString Property
Specifies a connection string.
Declaration
property ConnectionString: string read; write;
Property Value
| Type | Description |
|---|---|
| string | A connection string. |
Remarks
A connection string specifies the target database (SQL Server, PostgreSQL, SQLite, etc.) and all parameters required for connections.
Assign a valid connection string for a supported SQL database to the ConnectionString and enable the Active property to connect the TdxBackendDatabaseSQLConnection component to the database.
Code Examples
Connect to an SQL Database and Edit Report Templates
The following code example uses the TdxBackendDatabaseSQLConnection component to connect to a demo database (nwind.mdb), displays the Report Designer dialog, and saves all changes made to the UserReport.repx file:
uses
dxReport, // Declares the TdxReport component and related types
dxBackend.ConnectionString.SQL; // Declares the TdxBackendDatabaseSQLConnection component
// ...
procedure TMyForm.Button1Click(Sender: TObject);
var
ADataConnection: TdxBackendDatabaseSQLConnection;
AReport: TdxReport;
begin
ADataConnection := TdxBackendDatabaseSQLConnection.Create(Self);
try
ADataConnection.Name := 'DataConnection';
// Specify a connection string required to connect to a demo database (nwind.mdb)
ADataConnection.ConnectionString := 'XpoProvider=MSAccess;Provider=Microsoft.ACE.OLEDB.12.0;' +
'Data Source=C:\Users\Public\Documents\DevExpress VCL Demos\' +
'MegaDemos\Product Demos\ExpressPivotGrid\Data\nwind.mdb';
AReport := TdxReport.Create(Self);
try
AReport.ShowDesigner; // Displays the Web-based Report Designer dialog
AReport.Layout.SaveToFile('UserReport.repx'); // Saves the report template state to a file
finally
AReport.Free;
end;
finally
ADataConnection.Free;
end;
end;
Specify a PostgreSQL Connection String
The following code example demonstrates an OnClick event handler that configures a TdxBackendDatabaseSQLConnection component to access postgres (a test PostgreSQL database) and displays the Dashboard Designer dialog:
uses
dxDashboard.Control, // Declares the TdxDashboardControl component
dxBackend.ConnectionString.SQL; // Declares the TdxBackendDatabaseSQLConnection component
// ...
procedure TMyForm.cxButton1Click(Sender: TObject);
begin
dxBackendDatabaseSQLConnection1.Active := False; // Terminates the current connection (if one exists)
// Specify a user-friendly data connection name (for end-user dialogs) and a valid connection string
dxBackendDatabaseSQLConnection1.DisplayName := 'PostgreSQL Database Connection';
dxBackendDatabaseSQLConnection1.ConnectionString :=
'XpoProvider=Postgres;' + // Specifies the database engine type
'Server=127.0.0.1;' + // Specifies the database host IP address
'User ID=myuser;' + // Specifies a valid user name
'Password=123;' + // Specifies the corresponding password for the user name
'Database=dashboard_test;' + // Specifies the target database name
'Encoding=UNICODE'; // Sets UTF-8 as the required encoding
dxBackendDatabaseSQLConnection1.Active := True; // Connects to the "postgres" database
dxDashboardControl1.ShowDesigner; // Displays the Dashboard Designer dialog
end;
Connect to a Firebird SQL Database
The following code example demonstrates an OnClick event handler that configures a TdxBackendDatabaseSQLConnection component used to access the EMPLOYEE.FDB test Firebird database and to display the Dashboard Designer dialog:
uses
dxDashboard.Control, // Declares the TdxDashboardControl component
dxBackend.ConnectionString.SQL; // Declares the TdxBackendDatabaseSQLConnection component
// ...
procedure TMyForm.cxButton1Click(Sender: TObject);
begin
dxBackendDatabaseSQLConnection1.Active := False; // Terminates the current connection (if one exists)
// Specify a user-friendly data connection name (for end-user dialogs) and a valid connection string
dxBackendDatabaseSQLConnection1.DisplayName := 'Firebird Database Connection';
dxBackendDatabaseSQLConnection1.ConnectionString :=
'XpoProvider=Firebird;' + // Specifies the database engine type
'Datasource=localhost;' + // Specifies the database location (IP 127.0.0.1)
'User=SYSDBA;' + // Specifies a valid user name
'Password=password;' + // Specifies the corresponding password for the user names
'Database=C:\Program Files\Firebird\Firebird_5_0\examples\empbuild\EMPLOYEE.FDB;' +
'ServerType=0;Charset=NONE'; // Specifies additional parameters
dxBackendDatabaseSQLConnection1.Active := True; // Connects to the EMPLOYEE.FDB database
dxDashboardControl1.ShowDesigner; // Displays the Dashboard Designer dialog
end;
Default Value
The ConnectionString property’s default value is an empty string.