SQL Server + Jetbrains Rider for Mac (M1/Intel) - Updated for 2022 - Detailed Demo
SQL Server + Visual Studio for Mac (M1/Intel) - Updated for 2022 - Detailed Demo
This is only for sharing purpose. If you encounter any issues, please kindly do your due diligence Googling them first. I'm new to this and still learning too.
Based on a video tutorial by Valuetech Academy: https://www.youtube.com/watch?v=o5r3kFnsL-Q
-
Download and install Docker on Mac (Intel/Apple chip version based on your Mac's architecture)
-
Open Docker app, enter your Mac password to install helper, log in to your account
-
(Optional) Open Docker Preferences, lower the system RAM resource to minimum (if you only need minimum system resource for this purpose) -> Click OK then wait for Docker to restart
-
Open Terminal
a. If Apple Silicon Mac, type and enter
docker pull mcr.microsoft.com/azure-sql-edge:latest
b. If Intel Mac, type and enter
docker pull microsoft/mssql-server-linux
-
Choose any password that suits SqlServer's requirements (at least 8 chars with lowercase, uppercase, numbers, special symbols), e.g. Docker@123. Then still in Terminal
a. If Apple Silicon Mac, type and enter
docker run -d --name ms-sql-server -e "ACCEPT_EULA=Y" -e 'SA_PASSWORD=Docker@123' -p 1433:1433 mcr.microsoft.com/azure-sql-edge:latest
b. If Intel Mac, type and enter
docker run -d --name ms-sql-server 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Docker@123' -p 1433:1433 microsoft/mssql-server-linux
Note: If you want a different password, update the SA_PASSWORD part accordingly
-> If Docker runs it successfully, you'll see a long hash number displayed without any WARNING. Then to double check, head over to Docker > Containers / Apps, you'll see a Docker image with name mssql
running with a green status.
Otherwise, please refer to the comment section of the video tutorial to find out more workarounds for M1 Mac environment.
Note: This should work similarly with an alternative IDE. Here I'm using JetBrains Rider, but conceptually you can work out the logic with Visual Studio for Mac too. Otherwise please watch the demo for Visual Studio I listed above
-
Update the target framework of your ASP.NET Core project to the latest available SDK (e.g. .NET 6.0 at the time writing this gist)
-
Update your currently installed NuGet packages to the corresponding target SDK (e.g. 6.0.x)
-
👉 This step 3, and step 4 below is IMPORTANT! It's the very part where you actually configure your current ASP.NET Core project to work with your Docker mssql server. Now, you would edit your
appsettings.json
database connection string.For example: say your app's database context is named
ShopContext.cs
. Then inappsettings.json
, you would edit the connection string as follows:"ConnectionStrings": { "ShopContext": "Server=(localdb)\\mssqllocaldb;Database=GuitarShop;Trusted_Connection=True;MultipleActiveResultSets=true" /* Back up the above string somewhere, then update it as below with corresponding Database/Password info ... */ "ShopContext": "Server=localhost;Database=GuitarShop;User=sa;Password=Docker@123;" }
⚠️ ⚠️ ⚠️ Please note to NOT commit thisappsettings.json
edit to your group's repo, as it might break your group members' since you're using a Mac and they're on Windows. This workaround should be done locally on your macOS environment only.Also, if you chose a different password, change the Password part accordingly
-
Open Terminal, make sure you installed the EF CLI tools already. Otherwise google
install dotnet ef tools
. Then in Terminal directed to the project solution directorya. If the sample code comes with migrations already, just perform an update on your current database. To do that, type and enter
dotnet ef database update
-> Wait till the console saysDone.
b. If the sample code doesn't come equipped with migrations, you could try adding them manually. To do that, type and enter
dotnet ef migrations add <your_migration_name>
. Then go back to step 4a above.
This is the final step (albeit not necessarily needed for this tutorial), build and run the app. That's the whole tutorial there. Good luck!
Additionally, please also check out this article to install the ODBC driver for SQL Server on macOS if you encounter any driver-related issues.
Thank you for referring my post 🤝