Disconnect
Closes an existing MySQL database connection.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
info
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Inputs
- Connection Id - The unique identifier of the database connection to close. This is the connection ID returned by the Connect node.
Options
- None
Output
- None
How It Works
The Disconnect node closes an active MySQL database connection. When executed, the node:
- Validates the provided connection ID is not empty
- Retrieves the connection from the internal connections dictionary
- Removes the connection from the dictionary
- Closes the MySQL connection
- Releases database resources
Requirements
- A valid connection ID from a Connect node
- The connection must not have been previously closed
Error Handling
The node will return specific errors in the following cases:
- ErrInvalidArg - Connection ID is empty or not provided
- ErrNotFound - Connection not found (already closed or invalid ID)
Usage Examples
Basic Disconnect
// After completing all database operations
// Use the Disconnect node with the connection ID from Connect
Flow Structure
Connect → Query → Insert → Update → Disconnect
Always place the Disconnect node at the end of your database operations flow.
Using Try-Catch-Finally
Try
├─ Connect
├─ Query/Insert/Update Operations
└─ Catch (handle errors)
Finally
└─ Disconnect (always cleanup)
Common Use Cases
- Cleanup After Database Operations - Close connections when done with database work
- Resource Management - Release database connections to prevent connection pool exhaustion
- Error Recovery - Ensure connections are closed even when errors occur (use in Finally block)
- Connection Lifecycle Management - Properly manage connection open/close cycles
Tips for Effective Use
- Always Disconnect - Every Connect should have a corresponding Disconnect to prevent resource leaks
- Use Finally Blocks - Place Disconnect in a Finally node to ensure connections are closed even on errors
- Connection Reuse - Keep connections open for multiple operations, then disconnect at the end
- Don't Disconnect Too Early - Ensure all database operations complete before disconnecting
- Check Connection State - If using conditional logic, verify the connection exists before disconnecting
- Automated Cleanup - In long-running robots, implement proper connection lifecycle management
Common Errors and Solutions
Connection Not Found
Error: ErrNotFound: Connection not found
Solutions:
- Verify the connection ID is correct and matches the one from Connect node
- Ensure the Connect node executed successfully before Disconnect
- Check that you haven't already disconnected this connection
- Confirm the connection ID variable hasn't been overwritten
Connection ID Cannot Be Empty
Error: ErrInvalidArg: Connection ID cannot be empty
Solutions:
- Ensure the Connection Id input field is populated
- Verify the variable containing the connection ID has a value
- Check that the Connect node's output is properly connected to Disconnect
Connection Already Closed
Issue: Attempting to disconnect an already closed connection
Solutions:
- Use a boolean flag to track connection state
- Implement conditional logic to check if connection is still active
- Review your flow to ensure Disconnect is only called once
Best Practices
Resource Management Pattern
1. Connect (store conn_id)
2. Use Try-Catch-Finally
- Try: Database operations
- Catch: Error handling
- Finally: Disconnect
3. Ensure connection is always closed
Multiple Database Pattern
When working with multiple databases:
// Connect to both databases
const conn1 = $item.conn_id_db1;
const conn2 = $item.conn_id_db2;
// Perform cross-database operations
// ...
// Disconnect both (use separate Disconnect nodes)
// Disconnect with conn1
// Disconnect with conn2
Long-Running Automation
For robots that run continuously:
- Connect at the start of each transaction
- Perform database operations
- Disconnect after each transaction
- Don't keep connections open indefinitely
Transaction Cleanup
When using transactions:
Connect → Start Transaction → Operations → Commit → Disconnect
If transaction fails, still disconnect in the Finally block.
Connection Lifecycle
Good Pattern
Connect
↓
Store conn_id
↓
Multiple DB Operations (reuse conn_id)
↓
Disconnect (cleanup)
Anti-Pattern
Connect → Query → Disconnect → Connect → Insert → Disconnect
(Too many connect/disconnect cycles - inefficient)
Performance Considerations
- Connection Overhead - Opening/closing connections has overhead; reuse connections when possible
- Connection Limits - MySQL has a maximum connection limit; always close unused connections
- Memory Leaks - Failing to disconnect can cause memory leaks in long-running robots
- Network Resources - Open connections consume network resources; clean up promptly