Databases
IBM DB2 Database Management in VS Code
DBCode is a DB2 extension for VS Code: connect, browse schemas and data, write SQL with schema-aware autocomplete, and edit rows visually without leaving your editor. Install DBCode to get started, or see how it compares to standalone database tools.
Overview
Section titled “Overview”IBM Db2 is a family of data management products, including database servers, developed by IBM. Db2 is designed to store, analyze, and retrieve data efficiently, supporting both transactional and analytical workloads. With DBCode, you can connect to your Db2 databases, run queries, and manage your data directly from Visual Studio Code.
Authentication
Section titled “Authentication”IBM Db2 connections are typically made using a combination of hostname, port, database name, username, and password. Ensure you have the following information from your Db2 administrator or cloud provider:
- Hostname or IP address
- Port number (default is 50000)
- Database name
- Username
- Password
Connect to a Db2 Database
Section titled “Connect to a Db2 Database”To connect to a single IBM Db2 database, follow these general steps:
- Open the DBCode Extension: Launch Visual Studio Code and open the DBCode extension.
- Add a New Connection: Click on the “Add Connection” icon.
- Complete the New Connection Form: Choose IBM Db2 as the type, and enter the required connection details (hostname, port, database, username, password).
- Connect: Click save to connect to your IBM Db2 database.
- Start Managing Your Databases: Once connected, you can start managing your Db2 databases directly from Visual Studio Code.
For detailed instructions on connecting to IBM Db2, refer to the Connect article.
Debugging
Section titled “Debugging”DBCode can debug native Db2 SQL PL procedures with the VS Code debugger. See Debugger for how to start a session and use the shared debug UI. This section covers the Db2-specific scope and setup.
Required roles and privileges
Section titled “Required roles and privileges”The connection’s effective authorization must have the SYSDEBUG role. When the effective authorization is not the owner of the procedure, it must also have SYSDEBUGPRIVATE.
The authorization must be able to execute the native debugger procedures used by Db2. DBCode checks these requirements, but it does not grant roles, change privileges, or redeploy routines. Ask the database administrator to prepare the database according to the site’s access policy. The exact grant statements depend on how that database manages users, groups, and roles.
Compile a procedure for debugging
Section titled “Compile a procedure for debugging”Db2 must compile the procedure with debug information. On one database connection, call:
CALL SYSPROC.PSMD_SET_COMPILEMODE(1);Without releasing or replacing that connection, run the complete CREATE OR REPLACE PROCEDURE statement. Calling PSMD_SET_COMPILEMODE on one pooled connection and deploying on another does not prepare the procedure.
Then verify the exact deployed routine:
SELECT ROUTINESCHEMA, ROUTINENAME, SPECIFICNAME, DEBUG_MODEFROM SYSCAT.ROUTINESWHERE ROUTINESCHEMA = 'YOUR_SCHEMA' AND ROUTINENAME = 'YOUR_PROCEDURE';DEBUG_MODE must be ALLOW for the SPECIFICNAME you intend to debug. Re-run the same-connection deployment process after replacing a procedure if the catalog no longer reports ALLOW.
Configure callback reachability
Section titled “Configure callback reachability”Db2 calls back to the host that runs the DBCode extension. The database server must be able to open an inbound IPv4 TCP connection to that host.
The Db2 connection’s advanced settings include:
- Debugger callback host (
debuggerAdvertisedHost): Leave this empty to let DBCode probe candidate local IPv4 addresses. Set it to a hostname or IPv4 address that Db2 can reach when automatic discovery is not suitable. - Debugger callback port (
debuggerListenerPort): The default0uses an ephemeral port. Set a fixed port when an inbound firewall or port-forwarding rule needs a stable destination.
Check the network path from the database server’s point of view:
- With NAT, advertise the reachable address and forward the configured fixed port to the extension host.
- With a VPN, make sure the database can route back to the extension host’s VPN address.
- With a containerized database, remember that the container’s loopback address is not the host’s loopback address.
- In a remote VS Code workspace, the extension may run on the remote workspace host rather than your local computer. Db2 must reach the host where DBCode is running.
- Ordinary local SSH forwarding carries the database connection toward Db2, but it does not create this reverse callback path. Arrange a reachable address, VPN route, port forward, or separate reverse tunnel as appropriate for the environment.
DBCode tests the callback path before launch. If no candidate works, set the callback host explicitly and use a fixed port while checking routing and firewall rules.
Debugger features and limits
Section titled “Debugger features and limits”Db2 sessions support:
- Entry and executable-line breakpoints
- Continue, Step Over, Step Into, and Step Out
- Nested call stacks
- Watches by variable name
- Display of
INTEGER,VARCHAR, and SQLNULLvalues
In the first release, value editing is limited to a mutable INTEGER variable in the selected top stack frame. Other types and variables in older stack frames are read-only.
Pause is not supported while a procedure is running. Set a breakpoint before continuing if you need another stop point.
When you stop a paused or running session, DBCode asks Db2 to terminate the target using the cleanup operation for its current state, then releases the debugger listener and dedicated connection. If cleanup cannot be confirmed, the session ends with an error instead of reporting a successful stop.
Troubleshooting readiness failures
Section titled “Troubleshooting readiness failures”| Check | What to verify |
|---|---|
| Platform | The server is Db2 LUW. The debugger is validated against 12.1.0.0, but DBCode does not enforce a server-version allowlist. |
| Procedure | The target is a supported SQL PL procedure and its exact SYSCAT.ROUTINES row has DEBUG_MODE = 'ALLOW'. |
| Authorization | The effective authorization has SYSDEBUG, has SYSDEBUGPRIVATE for a procedure owned by another authorization, and can execute the required native debugger procedures. |
| Callback | Db2 can open an inbound IPv4 TCP connection to the advertised extension host and listener port. Check firewalls, NAT, VPN routing, containers, remote workspace placement, and tunnel direction. |