Overview
The Portal Self-Service Backend uses Microsoft SQL Server (MSSQL) as its database, with connections managed through themssql package. The application establishes a connection pool for efficient database operations.
Database Requirements
MSSQL Server
Microsoft SQL Server instance (2016 or later recommended)
Network Access
Server must be accessible from your application host
Authentication
Valid database credentials (user/password)
Database Created
Target database must exist before connecting
Required Environment Variables
The following environment variables must be configured for database connectivity:| Variable | Description | Example |
|---|---|---|
DB_USER | Database username | sa or app_user |
DB_PASSWORD | Database password | YourSecurePassword123! |
DB_SERVER | Database server hostname or IP | localhost or 192.168.1.100 |
DB_DATABASE | Database name | PortalSelfService |
DB_PORT | SQL Server port | 1433 (default) |
Connection Configuration
Review Database Configuration
The database configuration is defined in
src/config/db.config.js. Here’s the connection setup:src/config/db.config.js
Connection Pool Settings
The application uses a connection pool with the following configuration:
- Maximum connections: 10 concurrent connections
- Minimum connections: 0 (connections created on-demand)
- Idle timeout: 30 seconds before releasing idle connections
Connection Pool Initialization
The application establishes the database connection pool at startup:src/config/db.config.js
The connection is established asynchronously and verified during server startup in
server.js.Server Startup Verification
The application waits for the database connection before starting the HTTP server:server.js
Troubleshooting
Connection Refused
Check Network Connectivity
Ensure the database server is reachable:
Authentication Failed
Verify Credentials
- Double-check
DB_USERandDB_PASSWORD - Ensure the user has access to the specified database
- Check for special characters in password (may need escaping)
SQL Server Authentication
- Verify SQL Server authentication mode is enabled (not Windows-only)
- Confirm the user account is not locked or disabled
Connection Timeout
Verify SQL Server Configuration
Ensure TCP/IP protocol is enabled in SQL Server Configuration Manager.
Database Does Not Exist
Create the database using SQL Server Management Studio (SSMS) or via T-SQL:Common Issues
| Issue | Possible Cause | Solution |
|---|---|---|
ConnectionError: Failed to connect | Server unreachable | Verify DB_SERVER and network connectivity |
Login failed for user | Invalid credentials | Check DB_USER and DB_PASSWORD |
Cannot open database | Database doesn’t exist | Create database or verify DB_DATABASE name |
Connection timeout | Firewall blocking | Enable port 1433 in firewall rules |
Self signed certificate | SSL validation | Already handled with trustServerCertificate: true |
Testing the Connection
To verify your database configuration:Next Steps
Environment Configuration
Configure all environment variables including Azure AD
Deployment
Deploy your application to production