skip to Main Content

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


  1. Chosen as BEST ANSWER

    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


  2. 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

    Login or Signup to reply.
  3. 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;"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search