簡體   English   中英

無法使用 github 操作連接到 SQL 服務器

[英]Cannot connect to SQL Server with github action

自上周五以來,我一直試圖解決這個問題,我試圖從我的 .net 應用程序連接到 SQL 服務器數據庫。 誰能指出我做錯了什么?

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

這是連接字符串:

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

這是錯誤:

Microsoft.Data.SqlClient.SqlException (0x80131904):建立與 SQL 服務器的連接時發生與網絡相關或特定於實例的錯誤。 服務器未找到或無法訪問。 驗證實例名稱是否正確,並且 SQL 服務器配置為允許遠程連接。 (提供者:TCP 提供者,錯誤:35 - 捕獲到內部異常)

System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (00000005, 0xFFFDFFFF):名稱或服務未知

我試過用單引號和雙引號引用密碼。 使用 docker 運行創建 SQL 服務器容器。 所有這些都導致了此錯誤消息。

在連接字符串中將server更改為Data Source

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM