Logo

Connection String Setup

This guide explains how to configure the database connection string for your application.

Configuration Location

The connection string is configured in appsettings.json:

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=localhost;Database=MyApp;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=True"
  }
}

Connection String Components

Component Description Example
Server SQL Server instance name localhost, .\SQLEXPRESS, myserver.database.windows.net
Database Database name MyAppDb
Trusted_Connection Use Windows authentication True or False
User Id / Password SQL Server authentication User Id=sa;Password=***

Common Connection Strings

Local SQL Server (Windows Auth)

Server=localhost;Database=MyApp;Trusted_Connection=True;TrustServerCertificate=True

SQL Server Express

Server=.\SQLEXPRESS;Database=MyApp;Trusted_Connection=True;TrustServerCertificate=True

Azure SQL Database

Server=myserver.database.windows.net;Database=MyApp;User Id=myuser;Password=***;Encrypt=True

Troubleshooting

DATABASE_CONNECTION_FAILED
Check that:
  • SQL Server is running
  • The server name is correct
  • The database exists
  • Firewall allows connections
  • Credentials are correct (if using SQL auth)