1

In my Azure Pipeline I created a container using docker run using the below command:

docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Pa$$w0rd12' -p 1433:1433 -d mcr.microsoft.com/mssql/server:2017-latest-ubuntu

In another task I tried listing this container with a docker ps and it shows me the container as below:

/usr/bin/docker ps
CONTAINER ID   IMAGE                                               COMMAND                  CREATED        STATUS                  PORTS                                       NAMES
afca60eb6fde   mcr.microsoft.com/mssql/server:2017-latest-ubuntu   "/opt/mssql/bin/nonr…"   1 second ago   Up Less than a second   0.0.0.0:1433->1433/tcp, :::1433->1433/tcp   nostalgic_jemison
Finishing: list docker containers

Post that I'm trying to run my dotnet integration tests which uses the above container for the SQL server. These tests are supposed to create their own DB inside the servers, run the tests and delete them. But It fails while running the tests with the below error:

  Error Message:
   System.AggregateException : One or more errors occurred. (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)) (The following constructor parameters did not have matching fixture data: DatabaseSetup databaseSetup)
---- Microsoft.Data.SqlClient.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)
---- The following constructor parameters did not have matching fixture data: DatabaseSetup databaseSetup

The connection string I'm using in the integration tests are as below:

"Data Source=localhost,1433;Initial Catalog=dbname;User Id=SA;Password=Pa$$w0rd12"

I'm using Ubuntu 20.04 as the build agent. Same setup works fine on my local system on WSL with Ubuntu20.04

Update 1: I have replaced localhost with the IP address of the container in connection string. Works fine in WSL locally but it still throws the same error on Azure Pipelines.

Update 2: I have just noticed that the container stops when I run dotnet test in the pipeline. I can see container running before dotnet test but can't see the container active after dotnet test

User1224
  • 21
  • 2

1 Answers1

0

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)

You can follow the below steps to troubleshoot the error:

  1. Verify that the instance is running

  2. Verify that the SQL Server Browser service is running

  3. Verify the server name in the connection string

  4. Verify the aliases on the client machines

  5. Verify the firewall configuration

  6. Verify the enabled protocols on SQL Server

  7. Test TCP/IP connectivity

  8. Test local connection

  9. Test remote connection

The following constructor parameters did not have matching fixture

data: DatabaseSetup databaseSetup

You can refer to The following constructor parameters did not have matching fixture data for more help.

jinkc-MSFT
  • 101
  • 3
  • Hi, Thanks for the response. As mentioned in the question. The SQL server is running in a container in an Azure DevOps agent on Ubuntu20.04. This whole setup works well on my system without any errors – User1224 Jun 15 '22 at 11:13