skip to Main Content

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:

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:

<!--<add
    key = "***.Data.ConnectionString"
    value = "Server=****, 1433; Database=***;User ID=***;Password=***;" />-->

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

<!--<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.

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 SQL Server.

Any help would be great.

2

Answers


  1. Chosen as BEST ANSWER

    I further dug the IIS application logs in the docker and I found, it throws this error while trying to authenticate.

    Event code: 4005
    Event message: Forms authentication failed for the request. Reason: The ticket supplied was invalid.
    Event time: 29/07/2024 17:02:30
    Event time (UTC): 29/07/2024 16:02:30
    Event ID: 35ad1e99c62b4667b240c19a0c3e945f
    Event sequence: 2
    Event occurrence: 1
    Event detail code: 50201
    
    Application information:
        Application domain: /LM/W3SVC/1/ROOT-1-133667425492016462
        Trust level: Full
        Application Virtual Path: /
        Application Path: C:inetpubwwwroot
        Machine name: EC7A5C0027E8
    
    Process information:
        Process ID: 2624
        Process name: w3wp.exe
        Account name: IIS APPPOOLDefaultAppPool
    
    Request information:
        Request URL: http://localhost/default.aspx
        Request path: /default.aspx
        User host address: 192.168.1.21
        User:
        Is authenticated: False
        Authentication Type:
        Thread account name: IIS APPPOOLDefaultAppPool
    
    Name to authenticate:
    
    Custom event details:
    

  2. Finally, I found the solution, there was no issue regarding the sql server. Everything was set perfectly, like tcpip settings in sql server configuration, firewall inbound rule for 1433 port, allow remote connection in sql server etc.

    The actual problem was that I was unable to see the logs to find out where the problem is happening. After so many days I found that app.log resides in inetpub/wwwroot directory which has got detailed exception log about the error which guided me that there is a problem in the directory structure in dockerfile, due to which the application is unable to find the localisation and resources folder.

    I corrected my dockerfile to create correct directory structure under inetpub/wwwroot and it worked.

    Anyone struggling with the error with dockerfile, here is my version:

    FROM mcr.microsoft.com/dotnet/framework/aspnet:3.5-windowsservercore-ltsc2016
    
    WORKDIR /inetpub/wwwroot/***/***/auth
    COPY auth/. .
    
    WORKDIR /inetpub/wwwroot/***/**/<app dir>/
    COPY admin/. /inetpub/wwwroot/**/**/<app dir>/.
    
    RUN c:WindowsSystem32inetsrvappcmd.exe add app /site.name:"Default Web Site" /path:/***/**/<app dir>/physicalPath:C:inetpubwwwroot******<app dir>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search