To eliminate this error, write below statement after every stored procedure is executed,

statement1.close();

If there are multiple external databases on different servers, then you can create separate DSN to connect to each server. This connection information can be stored in a master table containing the DSN name, the database name.

The X++ code can then use the connection details from the master table as shown below.