Connecting to an Application
When the Amt COM Module has been loaded into memory and the appropriate object created a connection to an application has to be established before any Forms can be accessed. This is done by opening a session to the appropriate Transaction server, of the COBOL Application.
The following property must be defined before attempting the connection:
- BaseAddress: Defines the Transaction Server address of the Cobol Application.
Visual Basic
In Visual Basic Script the code to do this is (including an optional error message):
Dim ResCode
COBOLapp.BaseAddress = "Grpc:<TransactionServer>:<port>"
ResCode = COBOLapp.OpenSession()
If ResCode = 1 Then
WScript.echo("Connected")
Else
WScript.echo("Not Connected")
WScript.echo("Result code is: " & ResCode)
End If
Powershell
In Powershell the code to do this is:
Add-Type -Path '<Path to COMModule>\AmtCOMModule.dll'
# Create an AmtComConnection object
$COBOLapp = New-Object Asysco.Amt.COMModule.AmtCOMConnection
# The transaction server to connect to
$COBOLapp.BaseAddress = 'Grpc:<TransactionServer>:<port>'
# Try to connect
if ($COBOLapp.OpenSession() -eq 1) {
Write-Host 'Connected'
} else {
Write-Host 'Connection Failed!!!!!'
}
C# (.NET)
In C# the example code is for a WPF program named COMModule_Test, with a Button to connect and a TextBox to display the result.
using System.Windows;
using Asysco.Amt.COMModule;
namespace COMModule_Test {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow :Window {
private AmtCOMConnection cobolApp = new AmtCOMConnection();
public AmtCOMConnection CobolApp { get { return cobolApp; } set { cobolApp = value; } }
public MainWindow () {
InitializeComponent();
}
private void btnConnect_Click (Object sender, RoutedEventArgs e) {
//The base address is the transaction server.
CobolApp.BaseAddress = "Grpc:<TransactionServer>:<port>";
if (CobolApp.OpenSession() == ResponseCode.Ok) {
edtStatus.Text = "Connected";
} else {
edtStatus.Text = "Unable to connect";
}
}
}
}