IDalCommand.Connection

Syntax

Connection: IDalConnection;

Connection: Prognoz.Platform.Interop.Dal.IDalConnection;

Description

The Connection property returns the current database connection.

Example

Executing the example requires that the repository contains a database with the DB identifier and a procedure with the Procedure identifier.

Add links to the Dal, Db, Collections, Metabase system assemblies.

Sub UserProc;
Var
    MB: IMetabase;
    DB: IDatabaseInstance;
    Com: IDalCommand;
    Conn: IDalConnection;
    Proc: IDalProcedures;
    ParamInfo, ValueParam: IArrayList;
    i: Integer;
    ProcFields: IDalCursorFields;
    ProcField: IDalCursorField;
Begin
    MB := MetabaseClass.Active;
    DB := MB.ItemById(
"DB").Open(NullAs IDatabaseInstance;
    Com := DB.Connection.CreateCommand(
"");
    Conn := Com.Connection;
    Proc := Conn.Procedures(
"Procedure");
    ParamInfo := 
New ArrayList.Create;
    ValueParam := 
New ArrayList.Create;
    ProcFields := Proc.Fields;
    
While Not Proc.Eof Do
        
For i := 0 To ProcFields.Count - 1 Do
            ProcField := ProcFields.Item(i);
            ParamInfo.Add(ProcField.Name);
            ValueParam.Add(ProcField.Value);
        
End For;
        Proc.Next;
    
End While;
    Conn.Close;
    Com.Close;
    
For i := 0 To ParamInfo.Count - 1 Do
        Debug.Write(ParamInfo.Item(i));
        Debug.Write(
" = ");
        Debug.WriteLine(ValueParam.Item(i));
    
End For;
End Sub UserProc;

Imports Prognoz.Platform.Interop.Dal;
Imports Prognoz.Platform.Interop.Db;
Imports Prognoz.Platform.Interop.ForeCollections;
Imports Prognoz.Platform.Interop.Metabase;

Public Shared Sub Main(Params: StartParams);
Var
    MB: IMetabase;
    DB: IDatabaseInstance;
    Com: IDalCommand;
    Conn: IDalConnection;
    Proc: IDalProcedures;
    ParamInfo, ValueParam: IArrayList = 
New ArrayListClass();
    i: Integer;
    ProcFields: IDalCursorFields;
    ProcField: IDalCursorField;
Begin
    MB := Params.Metabase;
    DB := MB.ItemById[
"DB"].Open(NullAs IDatabaseInstance;
    Com := DB.Connection.CreateCommand(
"");
    Conn := Com.Connection;
    Proc := Conn.Procedures[
"Procedure"];
    ProcFields := Proc.Fields;
    
While Not Proc.Eof() Do
        
For i := 0 To ProcFields.Count - 1 Do
            ProcField := ProcFields.Item[i];
            ParamInfo.Add(ProcField.Name);
            ValueParam.Add(ProcField.Value);
        
End For;
        Proc.Next();
    
End While;
    Conn.Close();
    Com.Close();
    
For i := 0 To ParamInfo.Count - 1 Do
        System.Diagnostics.Debug.Write(ParamInfo.Item[i]);
        System.Diagnostics.Debug.Write(
" = ");
        System.Diagnostics.Debug.WriteLine(ValueParam.Item[i]);
    
End For;
End Sub;

After executing the example, the connection to the specified database is established. The cursor that contains information about the procedure is obtained on the basis of this connection, then this information is read into the ParamInfo and ValueParam arrays. The obtained information is displayed in the development environment console.

See also:

IDalCommand