CreateDescriptor: IDalConnectionDescriptor;
The CreateDescriptor method creates a database server connection description.
The type of driver in use depends on the class, which was used to initialize an object described by the IDalDriver interface. Enter connection parameters and create a connection using the IDalConnectionDescriptor.CreateConnection method. The parameters required for different drivers are different and can be obtained using the IDalConnectionDescriptor.Params property.
Below are the examples of connection to DBMS servers in the Fore language using various drivers of the Dal assembly. Connection results are displayed in the development environment console.
Add a link to the Dal system assembly.
Executing the example requires a server based on ClickHouse DBMS. Connection is established to a default database.
Sub CLICKHOUSESample;
Var
Driver: IDalDriver;
ConDescriptor: IDalConnectionDescriptor;
Params: IDalConnectionDescriptorParams;
Connection: IDalConnection;
Begin
Driver := New DalClickHouseDriver.Create;
ConDescriptor := Driver.CreateDescriptor;
// Regular connection
Params := ConDescriptor.Params;
Params.Find("Host BSTR").Value := "CHServer";
Params.Find("Database").Value := "default";
Params.Find("User Name").Value := "default";
Params.Find("Password").Value := "default";
// or
// SSL connection
Params.Find("Host BSTR").Value := "CHServer";
Params.Find("Database").Value := "default";
Params.Find("User Name").Value := "User";
Params.Find("Password").Value := "Password";
Params.Find("PingBeforeQuery").Value := "TRUE";
Params.Find("Port").Value := "9440";
Params.Find("SslEnabled").Value := "true";
Params.Find("SslUseDefaultCALocations").Value := "false";
Params.Find("SslPathToCAFiles").Value := "/opt/foresight/fp10.x-biserver/ssl/clickhouse.crt";
Params.Find("SslSkipVerification").Value := "true";
// Create a connection
Connection := ConDescriptor.CreateConnection;
Debug.WriteLine(Connection.IsDisconnected ? "No connection." : "Connection created.");
Connection.Close;
End Sub CLICKHOUSESample;
Executing the example requires a server based on Microsoft SQL Server DBMS. A database named WAREHOUSE is created on the server.
Sub MSSQL2012Sample;
Var
Driver: IDalDriver;
ConDescriptor: IDalConnectionDescriptor;
Params: IDalConnectionDescriptorParams;
Connection: IDalConnection;
Begin
Driver := New DalMsSql2012Driver.Create;
ConDescriptor := Driver.CreateDescriptor;
// Connection parameters
Params := ConDescriptor.Params;
Params.Find("Host BSTR").Value := "MSServer";
Params.Find("Database").Value := "WAREHOUSE";
Params.Find("User Name").Value := "User";
Params.Find("Password").Value := "Password";
// Create a connection
Connection := ConDescriptor.CreateConnection;
Debug.WriteLine(Connection.IsDisconnected ? "No connection." : "Connection created.");
Connection.Close;
End Sub MSSQL2012Sample;
Executing the example requires a server based on Microsoft SQL Server DBMS. A database named WAREHOUSE is created on the server. The operating system must have Microsoft SQL Server ODBC driver installed.
Sub MSSQL2012ODBCSample;
Var
Driver: IDalDriver;
ConDescriptor: IDalConnectionDescriptor;
Params: IDalConnectionDescriptorParams;
Connection: IDalConnection;
Begin
Driver := New DalMsSql2012ODBCDriver.Create;
ConDescriptor := Driver.CreateDescriptor;
// Connection parameters
Params := ConDescriptor.Params;
Params.Find("Host BSTR").Value := "MSServer";
Params.Find("Database").Value := "WAREHOUSE";
Params.Find("User Name").Value := "User";
Params.Find("Password").Value := "Password";
Params.Find("ODBCParams").Value := "MultiSubnetFailover=Yes;ApplicationIntent=ReadOnly";
// Create a connection
Connection := ConDescriptor.CreateConnection;
Debug.WriteLine(Connection.IsDisconnected ? "No connection." : "Connection created.");
Connection.Close;
End Sub MSSQL2012ODBCSample;
Executing the example requires a server based on Microsoft SQL Server DBMS. A database named WAREHOUSE is created on the server. The operating system must have PostgreSQL ODBC driver installed. A custom DSN named PostgreSQL35W is also created. The example displays various options of setting connection settings using ODBC driver. To execute the example, select one setup option and comment the rest of the options.
Sub ODBCSample;
Var
Driver: IDalDriver;
ConDesc: IDalConnectionDescriptor;
ODBCConnection: IDalODBCConnectionDescriptor;
Connection: IDalConnection;
Begin
Driver := New DalODBCDriver.Create;
ConDesc := Driver.CreateDescriptor;
ODBCConnection := ConDesc As IDalODBCConnectionDescriptor;
/// <summary>
/// Below are various options for setting connection parameters (1-3).
/// Each option is used independently on other options,
/// one can also use combination of options for setting parameters
/// via the ODBCParams and ODBCParamValue (4) properties.
/// </summary>
// 1. Custom DSN
ODBCConnection.ODBCParams := "DSN=PostgreSQL35W";
// 2. Full connection string
ODBCConnection.ODBCParams := "DRIVER={PostgreSQL Unicode};SERVER=127.0.0.1;DATABASE=WAREHOUSE;UID=user;PWD=password;";
// 3. Set parameter value named DSN or specific connection parameters
ODBCConnection.ODBCParamValue("DSN") := "PostgreSQL35W";
// or
ODBCConnection.ODBCParamValue("DRIVER") := "{PostgreSQL Unicode}";
ODBCConnection.ODBCParamValue("SERVER") := "127.0.0.1";
ODBCConnection.ODBCParamValue("DATABASE") := "WAREHOUSE";
ODBCConnection.ODBCParamValue("UID") := "user";
ODBCConnection.ODBCParamValue("PWD") := "password";
// 4. Combination of options
ODBCConnection.ODBCParams := "DRIVER={PostgreSQL Unicode};SERVER=127.0.0.1;DATABASE=WAREHOUSE";
ODBCConnection.ODBCParamValue("UID") := "user";
ODBCConnection.ODBCParamValue("PWD") := "password";
// Create a connection
Connection := ConDesc.CreateConnection;
Debug.WriteLine(Connection.IsDisconnected ? "No connection." : "Connection created.");
Connection.Close;
End Sub ODBCSample;
Executing the example requires a server based on Oracle DBMS. A database named WAREHOUSE is created on the server.
Sub ORCL8Sample;
Var
Driver: IDalDriver;
ConDescriptor: IDalConnectionDescriptor;
Params: IDalConnectionDescriptorParams;
Connection: IDalConnection;
Begin
Driver := New DalOrcl8Driver.Create;
ConDescriptor := Driver.CreateDescriptor;
// Connection parameters
Params := ConDescriptor.Params;
Params.Find("Host BSTR").Value := "ORCLServer";
Params.Find("Schema").Value := "WAREHOUSE";
Params.Find("User Name").Value := "User";
Params.Find("Password").Value := "Password";
// Create a connection
Connection := ConDescriptor.CreateConnection;
Debug.WriteLine(Connection.IsDisconnected ? "No connection." : "Connection created.");
Connection.Close;
End Sub ORCL8Sample;
Executing the example requires a server based on Microsoft SQL Server DBMS. A database named WAREHOUSE is created on the server.
Sub POSTGRESQLSample;
Var
Driver: IDalDriver;
ConDescriptor: IDalConnectionDescriptor;
Params: IDalConnectionDescriptorParams;
Connection: IDalConnection;
Begin
Driver := New DalPostgresDriver.Create;
ConDescriptor := Driver.CreateDescriptor;
// Connection parameters
Params := ConDescriptor.Params;
Params.Find("Host BSTR").Value := "PGServer";
Params.Find("dbname").Value := "WAREHOUSE";
Params.Find("User Name").Value := "User";
Params.Find("Password").Value := "Password";
// Create a connection
Connection := ConDescriptor.CreateConnection;
Debug.WriteLine(Connection.IsDisconnected ? "No connection." : "Connection created.");
Connection.Close;
End Sub POSTGRESQLSample;
Executing the example requires the file d:\Work\Sqlite\warehouse containing an SQLite database.
Sub SQLiteSample;
Var
Driver: IDalDriver;
ConDescriptor: IDalConnectionDescriptor;
Params: IDalConnectionDescriptorParams;
Connection: IDalConnection;
Begin
Driver := New DalSQLiteDriver.Create;
ConDescriptor := Driver.CreateDescriptor;
// Connection parameters
Params := ConDescriptor.Params;
Params.Find("Database").Value := "d:\Work\Sqlite\warehouse";
// Create a connection
Connection := ConDescriptor.CreateConnection;
Debug.WriteLine(Connection.IsDisconnected ? "No connection." : "Connection created.");
Connection.Close;
End Sub SQLiteSample;
See also:
DalClickHouseDriver