Cannot connect to SQL Server with github action

0

I have been trying to figure this out since last Friday, I am trying to connect to a SQL Server database from my .net app. Can anyone point out what I am doing wrong?

name: .NET
on:
  push:
    branches: [ CI567 ]
  pull_request:
    branches: [ CI567 ]

jobs:
  container-job:
    runs-on: ubuntu-latest
    services:
      sql.data:
        image: mcr.microsoft.com/mssql/server:2019-latest
        env:
          SA_PASSWORD: WhatAmIDoing&Wrong
          ACCEPT_EULA: Y
        ports:
          - "1433:1433"
    steps:
    - name: list container images
      run: docker ps -a
    - name: checkout
      uses: actions/checkout@v2
    - name: Setup .NET
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 5.0.x
    - name: Restore dependencies
      run: dotnet restore
      working-directory: ./LabManager
    - name: Build
      run: dotnet build --no-restore
      working-directory: ./LabManager
    - name: Restore donettool
      run: dotnet tool install --global dotnet-ef
      working-directory: ./LabManager
    - name: update database
      run: dotnet-ef database update --no-build
      working-directory: ./LabManager
    - name: Test
      run: dotnet test --no-build --verbosity normal
      working-directory: ./LabManager

Here's the connection string:

  "ConnectionStrings": {
    "Test": "server=localhost,1433; User Id='SA'; Password='WhatAmIDoing&Wrong'"
  },

This is the error:

Microsoft.Data.SqlClient.SqlException (0x80131904): 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: 35 - An internal exception was caught)

System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (00000005, 0xFFFDFFFF): Name or service not known

I have tried quoting the password with single and double. using docker run to create a SQL Server container. All resulted in this error message.

c#
.net
docker
github-actions
asked on Stack Overflow May 11, 2021 by He Chuan • edited May 12, 2021 by He Chuan

1 Answer

0

Change the server to Data Source in the connection string

"ConnectionStrings": {
    "Test": "Data Source=localhost,1433; User Id='SA'; Password='WhatAmIDoing&Wrong'"
  },
answered on Stack Overflow May 16, 2021 by frank_lee

User contributions licensed under CC BY-SA 3.0