Setting up SQL Server database locally in Azure DevOps build pipeline

I need help with configuring a local SQL Server database for my Azure DevOps pipeline testing.

Background:
I’m working on a C# application that requires a SQL Server database connection. My team needs to run automated tests through Azure DevOps pipelines using windows-latest hosted agents. The application has a utility that restores the database from backup files and runs SQL scripts to populate test data.

The Problem:
Most documentation I’ve found covers connecting to external SQL servers or manual installations. I haven’t seen good examples of creating a temporary SQL instance directly inside the pipeline VM for testing purposes.

Current Setup:
Locally we use SQL Server Express 15.0.2130 and manage everything through SSMS. Our app depends on database data during startup, so we need the database ready before running tests.

Question:
What’s the best approach to spin up a SQL Server instance within the Azure DevOps pipeline VM? Is there a reason this approach isn’t commonly documented? I’m looking for a way to create a temporary database environment that gets torn down after tests complete.

Any guidance on implementing this would be really helpful. I want to make sure our CI/CD process can fully validate the application without external dependencies.

have you looked into using SQL Server Docker containers? they’re super fast to set up in your pipeline and keep everything isolated. what kinda errors pop up when the db isn’t ready? maybe connection timeouts or something else?

Hit this same issue last year migrating our legacy app tests to Azure DevOps. Here’s what I found: windows-latest agents come with SQL Server Express pre-installed, not just LocalDB. You can use PowerShell tasks to fire up the SQL Server service and create your database. Most teams don’t talk about this because they prefer containerized solutions for portability. But since you’re already running SQL Server Express locally, just use Set-Service -Name 'MSSQL$SQLEXPRESS' -StartupType Manual then Start-Service 'MSSQL$SQLEXPRESS' to get it running. We got way better compatibility with our existing backup restoration tools this way. LocalDB has some annoying limitations with certain SQL Server features.

windows-latest agents come with localdb already installed - way easier than messing with docker. Just use sqllocaldb create and sqllocaldb start in your yaml pipeline. I’ve done this before and it works great for CI testing without dealing with container overhead.