0

I am trying to connect my ASP.NET Core application to a remote SQL Server.

The application is deployed using IIS WScore 2016 image. When I run the application on my host, it's working, but in the container using this connection string :

Data Source=xx.xxx.xx.xx,1433;Initial Catalog=somedb;User Id=xxxxxx;Password=xxxxx;

or:

Server=xx.xx.xx.xx,PORT_NB;Database=DATABASE;User Id=USER;Password=PASSWORD

But no luck - I am using the default Docker network.

The error is like this:

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: TCP Provider, error: 0 - No such host is known.)

Notes:

  1. The server is allowing the remote connection
  2. All the connection strings are tested and can connect to the remote SQL Server from the application that runs on the host
  3. I have read the Docker documentation and they mentioned the IP forwarding but the example was on linux containers and I did not find any help about connecting the Windows containers to a remote SQL Server

Question

My concrete question is how to expose the container to the outside world and I can connection my container to the other remote services like a remote SQL Server?

Should I use host network or bridge with the IP forwarding?

Any help? Thanks

3 Answers 3

1

I changed the connection string to this :

 "ConnectionString": "Server=xx.xxx.xx.xx\\MSSQLSERVER,1433;Initial Catalog=Dbname;User Id=username;Password=xxxxxxx;"

then i restarted the AppPoll and it worked

Sign up to request clarification or add additional context in comments.

1 Comment

Great that this worked, but it doesn't seem like it's a container specific issue. I'm no SQL Server expert, so I can't comment on that.
0

What is the current network you're using for this container? If you used the default network, then you're using Network Address Translation (NAT). What that means is that you're using the host IP address to connect to the external network. So, your problem most likely is that the SQL Server is rejecting the connection from the IP of the container host.

The alternative on Windows is to use a different network drive. There are many options and I'd recommend you look at the option that better suits your needs: https://cda.ms/4nP

2 Comments

yes exactly the default network is NAT , i can ping the server on which sql server is running , also i tested the sql server IPALL port 1433 with Test-NetConnection and it succeed ,(from the container wich has 172 IP adress) but i can't ping the container from the server , i can't figure out what is the problem .
The reason you can't ping the container is because that IP address from the NAT network is only visible inside that network (which means container and host communication only). The translation of ports is what makes the connectivity between the container and the outside world. Unless you publish the ICMP (ping) ports (which you wouldn't be able to do as the host is using those ports) you can't ping a container on a NAT network.
0

I had the same error, try removing the port from the connection string as follows:

 "ConnectionString": "Server=ContainerName;Initial Catalog=Dbname;User Id=username;Password=xxxxxxx;"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.