Catch errors when opening a OleDb connection

schwenthschwenth Member Posts: 11
Hi all,

to read some values from an external database (AS400), I create a OleDb-connection to the AS400. That works realy great as long as the AS400 is available. What I try to do now is catch the errors that come up when I open the OleDb connection and the remote system is not available.
Here's a code example:

CREATE(AdoConn);
AdoConn.ConnectionString('Provider=IBMDA400.DataSource.1;Data Source=192.168.2.25;User ID=xxx;password=yyy');
AdoConn.Open();
CREATE(AdoRS);

If the remote system is not available, in the line --AdoConn.Open();--
a error is raised, but I have found no way to catch it.

Can somebody help?

Comments

  • jjanauskasjjanauskas Member Posts: 49
    just write own codeuint for that or any situation when you want to catch an error (actually I like to have a separate one codeuint in project for all error situation I want to handle)..

    The codeunit is smth like that:
    CODEUNIT OpenConnection
    
    Globals:
      Connection: ADO Connection;
      user, password: Text;
    
    OnRun() 
    [open connection]
    
    SetParams(user, password)
    [set global variables]
    
    GetConnection(var AConnection: ADO Connection)
    [return global ADO connection]
    

    And then use it:
    ...
    COMMIT;
    OpenConnection.SetParams(...);
    if OpenConnection.Run then
    begin
      OpenConnection.GetConnection(...);
      [do smth]
    
    end else  
      [error catcher]
    
    
Sign In or Register to comment.