How do you connect an ASP.NET Core app to Azure SQL?
Short answer: Use connection string in appsettings.json: "ConnectionStrings": { "DefaultConnection": "Server=tcp:myserver.database.windows.net,1433;Initial Catalog=MyDb;Persist Security Info=False;User ID=myuser;Password=mypassword;MultipleActiveResultSets=False;Encrypt =True;TrustServerCertificate=False;Connection Timeout=30;" } Inject DbContext using Entity Framework Core: builder.Services.AddDbContext<MyDbContext>(options =>…
Explain a bit more
options.UseSqlServer(builder.Configuration.GetConnectionString("Defa ultConnection")));
Example code
Use connection string in appsettings.json: "ConnectionStrings": { "DefaultConnection": "Server=tcp:myserver.database.windows.net,1433;Initial
Catalog=MyDb;Persist Security Info=False;User
ID=myuser;Password=mypassword;MultipleActiveResultSets=False;Encrypt
=True;TrustServerCertificate=False;Connection Timeout=30;"
} Inject DbContext using Entity Framework Core: builder.Services.AddDbContext<MyDbContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("Defa ultConnection")));
Real-world example (ShopNest)
ShopNest on Azure typically uses App Service + SQL Database + Blob Storage + Application Insights for monitoring.
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png