Overview
MasterLabel uses ADO.NET withSystem.Data.SqlClient to connect to SQL Server. The connection string is configured in appsettings.json and can be overridden per environment.
Configuration Structure
The connection string is defined in theConnectionStrings section of your configuration file:
The connection string key must be named
SqlConnection as this is referenced throughout the application code.Environment-Specific Configuration
Development (LocalDB)
For local development using SQL Server LocalDB: appsettings.Development.jsonProduction Configurations
Connection String Parameters
Common connection string parameters used by MasterLabel:| Parameter | Description | Example |
|---|---|---|
| Server | SQL Server instance name or address | (localdb)\\mssqllocaldb, localhost, 192.168.1.100 |
| Database | Database name | MasterLabelDB |
| Trusted_Connection | Use Windows Authentication | True or False |
| Integrated Security | Alternative to Trusted_Connection | True or SSPI |
| User Id | SQL Server login username | masterlabel_app |
| Password | SQL Server login password | YourPassword |
| TrustServerCertificate | Skip certificate validation (dev/test only) | True or False |
| Encrypt | Encrypt the connection | True or False |
| Connection Timeout | Connection timeout in seconds | 30 |
Security Best Practices
Use Environment Variables
Store sensitive connection strings in environment variables instead of configuration files:ASP.NET Core automatically reads connection strings from environment variables using the
__ (double underscore) separator.Verifying Configuration
To verify your connection string is working, you can test it usingsqlcmd:
Troubleshooting
Common Connection Issues
“Cannot open database “MasterLabelDB” requested by the login”- Ensure the database exists
- Verify the user has permissions on the database
- Add
TrustServerCertificate=Trueto your connection string for SQL Server 2022+
- Verify SQL Server authentication is enabled (for SQL Auth)
- Check username and password are correct
- Ensure the user exists and has proper permissions
MasterLabel uses the
System.Data.SqlClient NuGet package (v4.9.0) for database connectivity. This is compatible with .NET 8.0 and all modern SQL Server versions.