Back to Devexpress

TdxBackendDatabaseSQLConnection.ConnectionString Property

vcl-dxbackend-dot-connectionstring-dot-sql-dot-tdxbackenddatabasesqlconnection.md

latest21.7 KB
Original Source

TdxBackendDatabaseSQLConnection.ConnectionString Property

Specifies a connection string.

Declaration

delphi
property ConnectionString: string read; write;

Property Value

TypeDescription
string

A connection string.

|

Remarks

A connection string specifies the database engine type (SQLite, Microsoft SQL Server/Azure SQL, PostgreSQL, Oracle Database, MySQL, Firebird) and all parameters (database host IP, username, password, and so on) required for a connection.

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: Connection Strings

The following code examples demonstrate OnClick handlers that configure a TdxBackendDatabaseSQLConnection component to access different relational databases and to display the Dashboard Designer dialog:

SQLite

delphi
uses
  dxDashboard.Control, // Declares the TdxDashboardControl component
  dxBackend.ConnectionString.SQL; // Declares the TdxBackendDatabaseSQLConnection component
// ...

procedure TMyForm.cxDisplayDesignerButtonClick(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 := 'SQLite Database Connection';
  dxBackendDatabaseSQLConnection1.ConnectionString :=

    'XpoProvider=SQLite;' + // Specifies the database engine type
    'Data Source=C:\Users\Public\Documents\DevExpress VCL Demos\MegaDemos\' +
    'Product Demos\ExpressReports\Data\devav.sqlite3';

  dxBackendDatabaseSQLConnection1.Active := True; // Connects to the "devav.sqlite3" database
  dxDashboardControl1.ShowDesigner; // Displays the "Dashboard Designer" dialog
end;
cpp
#include "dxDashboard.Control.hpp" // Declares the TdxDashboardControl component
#include "dxBackend.ConnectionString.SQL.hpp" // Declares the TdxBackendDatabaseSQLConnection component

// Add the following linker directives to the corresponding CPP source file:
#pragma link "dxDashboard.Control" // Required to use dxDashboard.Control.hpp declarations
#if defined(_WIN64) // Required to use dxBackend.ConnectionString.SQL.hpp declarations
  #pragma link "dxBackend.ConnectionString.SQL.o"
#else
  #pragma link "dxBackend.ConnectionString.SQL.obj"
#endif
// ...

void __fastcall TMyForm::cxDisplayDesignerButtonClick(TObject *Sender)
{
  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 = "SQLite Database Connection";
  dxBackendDatabaseSQLConnection1->ConnectionString =

    L"XpoProvider=SQLite;" // Specifies the database engine type
    L"Data Source=C:\\Users\\Public\\Documents\\DevExpress VCL Demos\\MegaDemos\\"
    L"Product Demos\\ExpressReports\\Data\\devav.sqlite3";

  dxBackendDatabaseSQLConnection1->Active = true; // Connects to the "devav.sqlite3" database
  dxDashboardControl1->ShowDesigner(); // Displays the "Dashboard Designer" dialog
}

Microsoft SQL Server

delphi
uses
  dxDashboard.Control, // Declares the TdxDashboardControl component
  dxBackend.ConnectionString.SQL; // Declares the TdxBackendDatabaseSQLConnection component
// ...

procedure TMyForm.cxDisplayDesignerButtonClick(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 := 'Microsoft SQL Server Database Connection';
  dxBackendDatabaseSQLConnection1.ConnectionString :=

   'XpoProvider=MSSqlServer;' + // Specifies the database engine type
   'Data Source=(local);' + // Specifies the database host
   'User ID=username;' + // Specifies a valid user name
   'Password=password;' + // Specifies the corresponding password for the user name
   'Initial Catalog=database;' + // Specifies the initial catalog for the target database
   'Persist Security Info=true'; // Enables the "Persist Security Info" flag

  dxBackendDatabaseSQLConnection1.Active := True; // Connects to the test database
  dxDashboardControl1.ShowDesigner; // Displays the "Dashboard Designer" dialog
end;
cpp
#include "dxDashboard.Control.hpp" // Declares the TdxDashboardControl component
#include "dxBackend.ConnectionString.SQL.hpp" // Declares the TdxBackendDatabaseSQLConnection component

// Add the following linker directives to the corresponding CPP source file:
#pragma link "dxDashboard.Control" // Required to use dxDashboard.Control.hpp declarations
#if defined(_WIN64) // Required to use dxBackend.ConnectionString.SQL.hpp declarations
  #pragma link "dxBackend.ConnectionString.SQL.o"
#else
  #pragma link "dxBackend.ConnectionString.SQL.obj"
#endif
// ...

void __fastcall TMyForm::cxDisplayDesignerButtonClick(TObject *Sender)
{
  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 = "Microsoft SQL Server Database Connection";
  dxBackendDatabaseSQLConnection1->ConnectionString =

    L"XpoProvider=MSSqlServer;" // Specifies the database engine type
    L"Data Source=(local);" // Specifies the database host
    L"User ID=username;" // Specifies a valid user name
    L"Password=password;" // Specifies the corresponding password for the user name
    L"Initial Catalog=database;" // Specifies the initial catalog for the target database
    L"Persist Security Info=true;" // Enables the "Persist Security Info" flag

  dxBackendDatabaseSQLConnection1->Active = true; // Connects to the test database
  dxDashboardControl1->ShowDesigner(); // Displays the "Dashboard Designer" dialog
}

Microsoft SQL Azure

delphi
uses
  dxDashboard.Control, // Declares the TdxDashboardControl component
  dxBackend.ConnectionString.SQL; // Declares the TdxBackendDatabaseSQLConnection component
// ...

procedure TMyForm.cxDisplayDesignerButtonClick(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 := 'Microsoft Azure SQL Database Connection';
  dxBackendDatabaseSQLConnection1.ConnectionString :=

    'XpoProvider=MSSqlServer;' + // Specifies the database engine type
    'Data Source=tcp:YourServerName.database.windows.net;' + // Specifies the database host
    'User Id=azureuser;' + // Specifies a valid user name
    'Password=password;' + // Specifies the corresponding password for the user name
    'Initial Catalog=DXApplication384'; // Specifies the initial catalog for the target database

  dxBackendDatabaseSQLConnection1.Active := True; // Connects to the test database
  dxDashboardControl1.ShowDesigner; // Displays the "Dashboard Designer" dialog
end;
cpp
#include "dxDashboard.Control.hpp" // Declares the TdxDashboardControl component
#include "dxBackend.ConnectionString.SQL.hpp" // Declares the TdxBackendDatabaseSQLConnection component

// Add the following linker directives to the corresponding CPP source file:
#pragma link "dxDashboard.Control" // Required to use dxDashboard.Control.hpp declarations
#if defined(_WIN64) // Required to use dxBackend.ConnectionString.SQL.hpp declarations
  #pragma link "dxBackend.ConnectionString.SQL.o"
#else
  #pragma link "dxBackend.ConnectionString.SQL.obj"
#endif
// ...

void __fastcall TMyForm::cxDisplayDesignerButtonClick(TObject *Sender)
{
  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 = "Microsoft Azure SQL Database Connection";
  dxBackendDatabaseSQLConnection1->ConnectionString =

    L"XpoProvider=MSSqlServer;" // Specifies the database engine type
    L"Data Source=tcp:YourServerName.database.windows.net;" // Specifies the database host
    L"User Id=azureuser;" // Specifies a valid user name
    L"Password=password;" // Specifies the corresponding password for the user name
    L"Initial Catalog=DXApplication384"; // Specifies the initial catalog for the target database

  dxBackendDatabaseSQLConnection1->Active = true; // Connects to the test database
  dxDashboardControl1->ShowDesigner(); // Displays the "Dashboard Designer" dialog
}

MySQL

delphi
uses
  dxDashboard.Control, // Declares the TdxDashboardControl component
  dxBackend.ConnectionString.SQL; // Declares the TdBackendDatabaseSQLConnection component
// ...

procedure TMyForm.cxDisplayDesignerButtonClick(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 := 'MySQL Database Connection';
  dxBackendDatabaseSQLConnection1.ConnectionString :=

    'XpoProvider=MySql;' + // Specifies the database engine type
    'Server=127.0.0.1;' + // Specifies the database server host IP address
    'User ID=MyUserName;' + // Specifies a valid user name
    'Password=MyPassword;' + // Specifies the corresponding password for the user name
    'Database=MyDatabase;' + // Specifies the target database name
    'Persist Security Info=true;Charset=utf8'; // Specifies additional attributes

  dxBackendDatabaseSQLConnection1.Active := True; // Connects to the test database
  dxDashboardControl1.ShowDesigner; // Displays the "Dashboard Designer" dialog
end;
cpp
#include "dxDashboard.Control.hpp" // Declares the TdxDashboardControl component
#include "dxBackend.ConnectionString.SQL.hpp" // Declares the TdxBackendDatabaseSQLConnection component

// Add the following linker directives to the corresponding CPP source file:
#pragma link "dxDashboard.Control" // Required to use dxDashboard.Control.hpp declarations
#if defined(_WIN64) // Required to use dxBackend.ConnectionString.SQL.hpp declarations
  #pragma link "dxBackend.ConnectionString.SQL.o"
#else
  #pragma link "dxBackend.ConnectionString.SQL.obj"
#endif
// ...

void __fastcall TMyForm::cxDisplayDesignerButtonClick(TObject *Sender)
{
  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 = "Oracle Database Connection";
  dxBackendDatabaseSQLConnection1->ConnectionString =

    L"XpoProvider=MySql;" // Specifies the database engine type
    L"Server=127.0.0.1;" // Specifies the database server host IP address
    L"User ID=MyUserName;" // Specifies a valid user name
    L"Password=MyPassword;" // Specifies the corresponding password for the user name
    L"Database=MyDatabase;" // Specifies the target database name
    L"Persist Security Info=true;Charset=utf8"; // Specifies additional attributes

  dxBackendDatabaseSQLConnection1->Active = true; // Connects to the test database
  dxDashboardControl1->ShowDesigner(); // Displays the "Dashboard Designer" dialog
}

Oracle

delphi
uses
  dxDashboard.Control, // Declares the TdxDashboardControl component
  dxBackend.ConnectionString.SQL; // Declares the TdBackendDatabaseSQLConnection component
// ...

procedure TMyForm.cxDisplayDesignerButtonClick(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 := 'Oracle Database Connection';
  dxBackendDatabaseSQLConnection1.ConnectionString :=

    'XpoProvider=Oracle;' + // Specifies the database engine type
    'Data Source=TORCL;' + // Specifies the target database
    'User ID=MyUserName;' + // Specifies a valid user name
    'Password=MyPassword'; // Specifies the corresponding password for the user name

  dxBackendDatabaseSQLConnection1.Active := True; // Connects to the test database
  dxDashboardControl1.ShowDesigner; // Displays the "Dashboard Designer" dialog
end;
cpp
#include "dxDashboard.Control.hpp" // Declares the TdxDashboardControl component
#include "dxBackend.ConnectionString.SQL.hpp" // Declares the TdxBackendDatabaseSQLConnection component

// Add the following linker directives to the corresponding CPP source file:
#pragma link "dxDashboard.Control" // Required to use dxDashboard.Control.hpp declarations
#if defined(_WIN64) // Required to use dxBackend.ConnectionString.SQL.hpp declarations
  #pragma link "dxBackend.ConnectionString.SQL.o"
#else
  #pragma link "dxBackend.ConnectionString.SQL.obj"
#endif
// ...

void __fastcall TMyForm::cxDisplayDesignerButtonClick(TObject *Sender)
{
  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 = "Oracle Database Connection";
  dxBackendDatabaseSQLConnection1->ConnectionString =

    L"XpoProvider=Oracle;" // Specifies the database engine type
    L"Data Source=TORCL;" // Specifies the target database
    L"User ID=MyUserName;" // Specifies a valid user name
    L"Password=MyPassword"; // Specifies the corresponding password for the user name

  dxBackendDatabaseSQLConnection1->Active = true; // Connects to the test database
  dxDashboardControl1->ShowDesigner(); // Displays the "Dashboard Designer" dialog
}

PostgreSQL

delphi
uses
  dxDashboard.Control, // Declares the TdxDashboardControl component
  dxBackend.ConnectionString.SQL; // Declares the TdxBackendDatabaseSQLConnection component
// ...

procedure TMyForm.cxDisplayDesignerButtonClick(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 test database
  dxDashboardControl1.ShowDesigner; // Displays the "Dashboard Designer" dialog
end;
cpp
#include "dxDashboard.Control.hpp" // Declares the TdxDashboardControl component
#include "dxBackend.ConnectionString.SQL.hpp" // Declares the TdxBackendDatabaseSQLConnection component

// Add the following linker directives to the corresponding CPP source file:
#pragma link "dxDashboard.Control" // Required to use dxDashboard.Control.hpp declarations
#if defined(_WIN64) // Required to use dxBackend.ConnectionString.SQL.hpp declarations
  #pragma link "dxBackend.ConnectionString.SQL.o"
#else
  #pragma link "dxBackend.ConnectionString.SQL.obj"
#endif
// ...

void __fastcall TMyForm::cxDisplayDesignerButtonClick(TObject *Sender)
{
  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 =

    L"XpoProvider=Postgres;" // Specifies the database engine type
    L"Server=127.0.0.1;" // Specifies the database host IP address
    L"User ID=myuser;" // Specifies a valid user name
    L"Password=123;" // Specifies the corresponding password for the user name
    L"Database=dashboard_test;" // Specifies the target database name
    L"Encoding=UNICODE"; // Sets UTF-8 as the required encoding

  dxBackendDatabaseSQLConnection1->Active = true; // Connects to the test database
  dxDashboardControl1->ShowDesigner(); // Displays the "Dashboard Designer" dialog
}

Firebird

delphi
uses
  dxDashboard.Control, // Declares the TdxDashboardControl component
  dxBackend.ConnectionString.SQL; // Declares the TdxBackendDatabaseSQLConnection component
// ...

procedure TMyForm.cxDisplayDesignerButtonClick(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;
cpp
#include "dxDashboard.Control.hpp" // Declares the TdxDashboardControl component
#include "dxBackend.ConnectionString.SQL.hpp" // Declares the TdxBackendDatabaseSQLConnection component

// Add the following linker directives to the corresponding CPP source file:
#pragma link "dxDashboard.Control" // Required to use dxDashboard.Control.hpp declarations
#if defined(_WIN64) // Required to use dxBackend.ConnectionString.SQL.hpp declarations
  #pragma link "dxBackend.ConnectionString.SQL.o"
#else
  #pragma link "dxBackend.ConnectionString.SQL.obj"
#endif
// ...

void __fastcall TMyForm::cxDisplayDesignerButtonClick(TObject *Sender)
{
  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 =

    L"XpoProvider=Firebird;" // Specifies the database engine type
    L"Datasource=localhost;" // Specifies the database location (IP 127.0.0.1)
    L"User=SYSDBA;" // Specifies a valid user name
    L"Password=password;" // Specifies the corresponding password for the user name
    L"Database=C:\\Program Files\\Firebird\\Firebird_5_0\\examples\\empbuild\\EMPLOYEE.FDB;"
    L"ServerType=0;Charset=NONE"; // Specifies additional parameters

  dxBackendDatabaseSQLConnection1->Active = true; // Connects to the EMPLOYEE.FDB database
  dxDashboardControl1->ShowDesigner(); // Displays the "Dashboard Designer" dialog
}

Default Value

The ConnectionString property’s default value is an empty string.

See Also

TdxBackendCustomInMemoryJSONConnection.ConnectionString Property

TdxBackendDatabaseSQLConnection.DefaultEnableCustomSql Property

TdxBackendDatabaseSQLConnection Class

TdxBackendDatabaseSQLConnection Members

dxBackend.ConnectionString.SQL Unit