2025/02/21

[ASP.NET Core] 解決如何從 Docker Container 連至本機的 SQL Server

markdown ### 問題 在 Visual Studio 開發 ASP.NET Core 網站以 IIS Express 啟動時可正確連線 SQL Server 的資料庫。 近期改以 Docker 來啟動網站時,出現以下錯誤訊息:
SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 40 - Could not open a connection to SQL Server)