Experimenting with Ubuntu and Rider has been insightful, revealing that not everything is easier on Linux. One example? SQL Server Express. While it comes free with any Visual Studio setup on Windows, it isn’t available by default on Ubuntu.
Luckily, there are several ways to solve this problem. You could install the Linux version of SQL Server Express locally—or take the easier route and run it in a container.
Option 1: Complete Local Installation
A local installation lets you have SQL Server Express on your machine all the time, but it comes with a few drawbacks. The setup can be complex, requiring additional dependencies like LDAP libraries, which quickly add up. If, like me, you prefer a clean development environment, a full installation isn’t ideal.
Option 2: SQL Server Express in a Container
The container option is much simpler. You only run SQL Server Express when needed, without cluttering your environment. Here’s the setup script I used:
docker pull mcr.microsoft.com/mssql/server:2022-latest
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=topSecret#2024" \
-p 1433:1433 \
--hostname sql1 \
-d mcr.microsoft.com/mssql/server:2022-latest
docker ps
Updating Your Connection String
If you’re working with Rider or Visual Studio, you’ll need to update the connection string for the container-based server. Here’s how:
{
"ConnectionStrings": {
"AdminDbContextWindows": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=SampleDb;Integrated Security=True;Connect Timeout=30;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;Multi Subnet Failover=False;Max Pool Size=1000;",
"AdminDbContextLinux": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=SampleDb;Integrated Security=True;Connect Timeout=30;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;Multi Subnet Failover=False;Max Pool Size=1000;",
"AdminDbContext": "Server=tcp:127.0.0.1,1433;Initial Catalog=SampleDb;User ID=sa;Password=topSecret#2024;Connection Timeout=30;Encrypt=True;TrustServerCertificate=true;"
}
}
Note: Never commit sensitive information, like credentials, to version control. For production apps, consider using secure storage like AppSecrets.
Wrapping Up
With SQL Server Express running in a container, you can enjoy SQL development on Ubuntu without the hassle of a full installation. Happy coding!