Docker container can’t connect to SQL Server on a local server

I am trying to containerise a .NET framework 2.0 legacy application connecting to sql server on localhost outside the Docker, I am able to containerise the application but it doesn’t connect to sql server.

Even I comment out the connection string from the web.config, it tries to connect to sql server and I get the following error.

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: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server)

Here is my Dockerfile

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>FROM mcr.microsoft.com/dotnet/framework/aspnet:3.5-windowsservercore-ltsc2016
ARG source
EXPOSE 1433 //SQL-Server port
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN Remove-Item -Recurse C:inetpubwwwroot*
RUN Install-WindowsFeature -Name Web-ASP; Install-WindowsFeature -Name Web-ISAPI-Ext
RUN Install-WindowsFeature Web-Mgmt-Service ;New-ItemProperty -Path HKLM:softwaremicrosoftWebManagementServer -Name EnableRemoteManagement -Value 1 -Force; Set-Service -Name wmsvc -StartupType automatic;
RUN Install-WindowsFeature web-server, web-webserver
RUN Import-Module WebAdministration;Import-Module ServerManager
RUN New-Item c:/msi -ItemType Directory
RUN powershell -Command Invoke-WebRequest http://download.microsoft.com/download/D/D/E/DDE57C26-C62C-4C59-A1BB-31D58B36ADA2/rewrite_amd64_en-US.msi -OutFile c:/inetpub/rewrite_amd64_en-US.msi
RUN powershell -Command Start-Process c:/inetpub/rewrite_amd64_en-US.msi -ArgumentList "/qn" -Wait
RUN New-Item -ItemType directory -Path 'c:inetpubwwwrootRAFTSTestAdmin'
RUN Import-Module WebAdministration; New-WebVirtualDirectory -Site 'Default Web Site' -Name 'Admin' -PhysicalPath "c:inetpubwwwroot"
WORKDIR /inetpub/wwwroot/RAFTS/Test/Authentication
COPY authentication/. .
WORKDIR /inetpub/wwwroot
COPY admin/. .
RUN cmd /c icacls C:/inetpub/wwwroot /grant:r Everyone:F /t
</code>
<code>FROM mcr.microsoft.com/dotnet/framework/aspnet:3.5-windowsservercore-ltsc2016 ARG source EXPOSE 1433 //SQL-Server port SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] RUN Remove-Item -Recurse C:inetpubwwwroot* RUN Install-WindowsFeature -Name Web-ASP; Install-WindowsFeature -Name Web-ISAPI-Ext RUN Install-WindowsFeature Web-Mgmt-Service ;New-ItemProperty -Path HKLM:softwaremicrosoftWebManagementServer -Name EnableRemoteManagement -Value 1 -Force; Set-Service -Name wmsvc -StartupType automatic; RUN Install-WindowsFeature web-server, web-webserver RUN Import-Module WebAdministration;Import-Module ServerManager RUN New-Item c:/msi -ItemType Directory RUN powershell -Command Invoke-WebRequest http://download.microsoft.com/download/D/D/E/DDE57C26-C62C-4C59-A1BB-31D58B36ADA2/rewrite_amd64_en-US.msi -OutFile c:/inetpub/rewrite_amd64_en-US.msi RUN powershell -Command Start-Process c:/inetpub/rewrite_amd64_en-US.msi -ArgumentList "/qn" -Wait RUN New-Item -ItemType directory -Path 'c:inetpubwwwrootRAFTSTestAdmin' RUN Import-Module WebAdministration; New-WebVirtualDirectory -Site 'Default Web Site' -Name 'Admin' -PhysicalPath "c:inetpubwwwroot" WORKDIR /inetpub/wwwroot/RAFTS/Test/Authentication COPY authentication/. . WORKDIR /inetpub/wwwroot COPY admin/. . RUN cmd /c icacls C:/inetpub/wwwroot /grant:r Everyone:F /t </code>
FROM mcr.microsoft.com/dotnet/framework/aspnet:3.5-windowsservercore-ltsc2016
ARG source

EXPOSE 1433 //SQL-Server port

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN Remove-Item -Recurse C:inetpubwwwroot*
RUN Install-WindowsFeature -Name Web-ASP; Install-WindowsFeature -Name Web-ISAPI-Ext

RUN Install-WindowsFeature Web-Mgmt-Service ;New-ItemProperty -Path HKLM:softwaremicrosoftWebManagementServer -Name EnableRemoteManagement -Value 1 -Force; Set-Service -Name wmsvc -StartupType automatic;
RUN Install-WindowsFeature web-server, web-webserver
RUN Import-Module WebAdministration;Import-Module ServerManager

RUN New-Item c:/msi -ItemType Directory
RUN powershell -Command Invoke-WebRequest http://download.microsoft.com/download/D/D/E/DDE57C26-C62C-4C59-A1BB-31D58B36ADA2/rewrite_amd64_en-US.msi -OutFile c:/inetpub/rewrite_amd64_en-US.msi
RUN powershell -Command Start-Process c:/inetpub/rewrite_amd64_en-US.msi -ArgumentList "/qn" -Wait

RUN New-Item -ItemType directory -Path 'c:inetpubwwwrootRAFTSTestAdmin' 

RUN Import-Module WebAdministration; New-WebVirtualDirectory -Site 'Default Web Site' -Name 'Admin' -PhysicalPath "c:inetpubwwwroot"

WORKDIR /inetpub/wwwroot/RAFTS/Test/Authentication
COPY authentication/. .

WORKDIR /inetpub/wwwroot
COPY admin/. .

RUN cmd /c icacls C:/inetpub/wwwroot /grant:r Everyone:F /t

My connection string in web.config

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><!--<add
key = "***.Data.ConnectionString"
value = "Server=****, 1433; Database=***;User ID=***;Password=***;" />-->
</code>
<code><!--<add key = "***.Data.ConnectionString" value = "Server=****, 1433; Database=***;User ID=***;Password=***;" />--> </code>
<!--<add
    key = "***.Data.ConnectionString"
    value = "Server=****, 1433; Database=***;User ID=***;Password=***;" />-->

I have tried using host.docker.internal in the connection string

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><!--<add
key = "Stopford.RAFTS.Data.ConnectionString"
value = "Data Source=host.docker.internal,1433; Database=***;User ID=***;Password=****;" />-->
</code>
<code><!--<add key = "Stopford.RAFTS.Data.ConnectionString" value = "Data Source=host.docker.internal,1433; Database=***;User ID=***;Password=****;" />--> </code>
<!--<add
    key = "Stopford.RAFTS.Data.ConnectionString"
    value = "Data Source=host.docker.internal,1433; Database=***;User ID=***;Password=****;" />-->

but I am unable to ping host.docker.internal so there is no use of using in connection string.

I have tried every resort and every suggestion posted on stackoverflow and other blogs and internet resources but haven’t got any success so far.

My main worry is despite there is no reference to sql connection after I commented all the connection references in web.config, the code is still looking to connect to sqlserver.

Any help would be great as I am struggling to resolve this issue for last 2 weeks

New contributor

user3595854 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật