Connecting to a Data Source via a script or macro

Connecting to a data source via a script

When you are connecting to an external data source within a script you will need to use the DBConnect method to establish the connection. This method takes three arguments, Name (which is used to refer to the connection object for any subsequent actions), ServerType and a ConnectionString.

The server type argument allows the user to specify whether the connection is DDM or ADO. Distributed Data Management (DDM) is used to support databases on IBM i and IBM z hosts. It provides native record level access to databases that support DDM. ActiveX Data Objects (ADO) is used to support databases that support ODBC or OLE DB. Most major database vendors provide drivers that allow ADO access.

The connection string argument is used to specify all the information needed to connect to the database. The exact format of the Connection String will vary for different database providers and will vary between ADO and DDM databases.

To assist with the construction of connection strings, Newlook provides the Database Description window. This tool provides prompts for all the fields supported by the database provider being used. Once the Database Description window is exited, the complete connection string is automatically constructed and returned to Newlook in the appropriate format.

Once a connection is established the Open method can be called to open a specific recordset. The Source argument of this method specifies the source of the recordset. For DDM data sources, this argument specifies the database file, and optionally the file member. For ADO data sources, this argument is interpreted according to the value of the CommandType argument.

 

Connecting to a data source via a macro

When you are connecting to an external data source within a macro you will need to use the DBConnect action to establish the connection. This method takes three arguments, Connection (which is used to refer to the connection object for any subsequent actions), Server and a Connection String.

The server argument allows the user to specify whether the connection is DDM or ADO. Distributed Data Management (DDM) is used to support databases on IBM i and IBM z hosts. It provides native record level access to databases that support DDM. ActiveX Data Objects (ADO) is used to support databases that support ODBC or OLE DB. Most major database vendors provide drivers that allow ADO access.

The connection argument is used to specify all the information needed to connect to the database. The exact format of the Connection String will vary for different database providers and will vary between ADO and DDM databases.

To assist with the construction of connection strings, Newlook provides the Database Description window. This tool provides prompts for all the fields supported by the database provider being used. Once the Database Description window is exited, the complete connection string is automatically constructed and returned to Newlook in the appropriate format.

Once a connection is established the DBOpen action can be called to open a specific recordset. The Source argument of this method specifies the source of the recordset. For DDM data sources, this argument specifies the database file, and optionally the file member. For ADO data sources, this argument is interpreted according to the value of the Command Type argument.

See Also

Data Access | DBConnect method | DBConnect action | Creating, Modifying and Deleting records | Understanding Transactions