Click here to Skip to main content
15,885,855 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created an image of .Net Core Api demo named "WebAPIDemo" ,created a container for it and I am able to run it on my broswer on url localhost:8888/swagger. The docker is also installed on my machine itself. My application is successfully establishing connection to local database which is on my machine itself.

The connection string is as given below: Data Source=10.10.10.10\SQLEXPRESS,49172;Database=DBName;User ID=**;Password=****;MultipleActiveResultSets=true;

Now I am learning to use Docker Swarm and I have created a manager node "manager1" and a worker node "worker1". I have created a service for "WebAPIDemo" on manager node and i am able to access the swagger landing page on url for ex : 1.1.1.1:8888/swagger (lets say 1.1.1.1 is autogenerated Ip for manager node). But when i try to execute/invoke any endpoint from swagger page, I am getting below exception: "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)"

I am unable to understand why it is not extablishing communication with Sql Server. I am just a beginner and fairly new to docker and docker swarn concept. Am I missing any configuration settings or any app/sql related configuration that needs to be done here to connect to sql server?

Any suggestions?

Thanks in advance

What I have tried:

The connection string is as given below:
Data Source=10.10.10.10\SQLEXPRESS,49172;Database=DBName;User ID=**;Password=****;MultipleActiveResultSets=true;
Posted
Updated 20-Jun-19 6:57am

1 solution

Quote:
A network-related or instance-specific error occurred while establishing a connection to SQL Server.
This message tells is clearly that your server is not accessible from your machine. There can be several reasons for this problem, ranging from problems such as, incorrect connection string or server name, server being behind a firewall or you behind the firewall, or server not being up and running.

Since your problem happens to be from Docker environment, the issue might be that your service stack that is load balancing the SQL Server containers might not be available on the port or hostname that you are trying to access them from. Please check this guide and verify if you are correctly setting up the SQL Server in Docker, Configuration options for SQL Server on Docker - SQL Server | Microsoft Docs[^], it would be even better if you can just try to use a hello SQL Server for a tryout.

Please check these problems and then connect again with your Swagger services, it would work. You can see the list of similar threads on CodeProject on the right side under top experts list.

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...[^]
SQL Server 2017 containers on Kubernetes, OpenShift, and Docker Swarm | Microsoft Ignite 2017 | Channel 9[^]

If this is your connection string,
Data Source=10.10.10.10\SQLEXPRESS,49172;Database=DBName;User ID=**;Password=****;MultipleActiveResultSets=true;
Make sure that Docker is set to listen on that IP and has exposed the port, for other services to connect and interact with.
 
Share this answer
 
v3
Comments
Sunil Hanke 21-Jun-19 5:36am    
Thanks for the links you have provided.
As posted in question
I have already created an image of .Net Core Api project named "WebAPIDemo" ,created a container for it and its running absolutely fine.
I havent created an image for SQL server.I have SQL server on my local machine.
No issues in sql server connections as I have already done the TCP/IP port settings for SQL server for remote connections.
But the SQL connection issue arises after creating WebAPIDemo as a service in Docker swarm manage node .
I have created service by executing command "docker service create --replicas 1 -p 8800:82 --name WebAPIDemoService WebAPIDemo" in manager node.
FYI..Antivirus and firewall both are off.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900