Overview
AndanDo uses SQL Server as its primary database. The connection string is configured inappsettings.json under the ConnectionStrings section and is used throughout the application for data access.
Connection String Format
The database connection string follows the standard SQL Server format:appsettings.json
Connection String Parameters
Server
Server
Required - Specifies the SQL Server instance to connect to.
- Use
localhostor127.0.0.1for local development - Use IP address or hostname for remote servers
- Include instance name if not using default instance
Database
Database
Required - The name of the database to use.The database name for AndanDo is
AndandoDB.User Id & Password
User Id & Password
Required for SQL Authentication - Credentials for database access.
TrustServerCertificate
TrustServerCertificate
Recommended - Controls SSL certificate validation.
- Set to
truefor development or self-signed certificates - Set to
falsein production with valid SSL certificates - Required for SQL Server 2022+ and Azure SQL connections
Integrated Security (Optional)
Integrated Security (Optional)
Use Windows Authentication instead of SQL Authentication.When using Windows Authentication, omit
User Id and Password:Additional Parameters
Additional Parameters
Other useful connection string parameters:
Complete Connection String Examples
Using the Connection String in Code
TheDefaultConnection connection string is used throughout the application. Services retrieve it from IConfiguration:
AuthService.cs
Services Using Database Connection
The following services use theDefaultConnection connection string:
- AuthService (
Services/Auth/AuthService.cs:32) - User authentication and management - PasswordResetService (
Services/Auth/PasswordResetService.cs:28) - Password reset functionality - TourService (
Services/Tour/TourService.cs:160) - Tour data management - MailService (
Services/Mail/MailService.cs:40) - Internal mail system - ReviewService (
Services/Utility/ReviewService.cs:20) - Tour reviews and ratings - PostLikeService (
Services/Utility/PostLikeService.cs:23) - Post likes and reactions - FormularioTipoService (
Services/Utility/FormularioTipoService.cs:20) - Form type management - AppUpdateService (
Services/Utility/AppUpdateService.cs:18) - Application update tracking - SettingsService (
Services/Core/SettingsService.cs:22) - Application settings storage
All services validate that the connection string exists and throw an
InvalidOperationException if itβs not configured.Environment-Specific Configuration
Development (User Secrets)
Development (User Secrets)
For local development, use User Secrets to store the connection string:Verify the secret was set:
Production (Environment Variables)
Production (Environment Variables)
In production, use environment variables:Or in
appsettings.Production.json:Azure App Service
Azure App Service
In Azure App Service, configure the connection string in the portal:
- Go to Configuration β Connection strings
- Add a new connection string:
- Name:
DefaultConnection - Value: Your SQL connection string
- Type:
SQLServer
- Name:
- Click Save
Database Schema
TheAndandoDB database contains tables for:
- Users - User accounts and authentication
- Tours - Tour listings and details
- Bookings - Tour reservations and payments
- Reviews - Tour reviews and ratings
- Messages - Internal messaging system
- Posts & Likes - Community posts and interactions
- Settings - Application configuration
Database migrations and schema updates are managed manually through SQL scripts.
Troubleshooting
Connection string not found
Connection string not found
Error:
InvalidOperationException: Connection string 'DefaultConnection' not found.Solutions:- Verify
appsettings.jsoncontains theConnectionStringssection - Check for typos in the connection string name
- Ensure environment-specific configuration files are properly named
- Verify User Secrets are initialized if using them
Login failed for user
Login failed for user
Error:
SqlException: Login failed for user 'csuser'Solutions:- Verify username and password are correct
- Ensure SQL Server Authentication is enabled
- Check that the user has access to the database
- Verify the SQL Server instance is running
Certificate validation error
Certificate validation error
Error:
The certificate chain was issued by an authority that is not trustedSolution: Add TrustServerCertificate=true to the connection string.Cannot connect to server
Cannot connect to server
Error:
SqlException: A network-related or instance-specific error occurredSolutions:- Verify the server address is correct
- Ensure SQL Server is running
- Check firewall settings allow TCP/1433
- Verify SQL Server Browser service is running (for named instances)
- Test connectivity with SQL Server Management Studio