36

I'm trying to connect to my SQL Server instance running in my local computer using host.docker.internal (as recommended in https://docs.docker.com/docker-for-windows/networking/#use-cases-and-workarounds)

The host.docker.internal is successfully resolved to an IP, and it's ping-able

And I've opened up the port 1433 in my firewall configuration

Error message

Connection refused 192.168.65.2:1433

My connection string

Data Source=host.docker.internal,1433;Initial Catalog=;Persist Security Info=False;User ID=;Password=;MultipleActiveResultSets=True;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;

docker version

Client:
 Version:      18.03.1-ce
 API version:  1.37
 Go version:   go1.9.5
 Git commit:   9ee9f40
 Built:        Thu Apr 26 07:12:48 2018
 OS/Arch:      windows/amd64
 Experimental: false
 Orchestrator: swarm

Server:
 Engine:
  Version:      18.03.1-ce
  API version:  1.37 (minimum version 1.12)
  Go version:   go1.9.5
  Git commit:   9ee9f40
  Built:        Thu Apr 26 07:22:38 2018
  OS/Arch:      linux/amd64
  Experimental: true

Docker for windows version

Docker for windows

Kien Chu
  • 4,735
  • 1
  • 17
  • 31

1 Answers1

27

If anyone have similar problem, here's how I solve it

  • Open SQL Server Configuration Manager
  • Enable TCP/IP in Server Network Configuration
  • Restart SQL Service Service

TCP/IP

If it's still not working, there are a few more things to check

  1. Firewall (open port 1433)
  2. Enable remote connections to your sql server

enter image description here

Kien Chu
  • 4,735
  • 1
  • 17
  • 31
  • 14
    In my case I had to do few additional steps, because I wanted to access SQL Server named instance on my host machine. Trying to access "host.docker.internal\SQLSERVER,1433" data source was always a failure. Eventually I've found solution that allows to connect to the named instance. 1. Get the port of the named instance [How to do it](https://www.mssqltips.com/sqlservertip/2495/identify-sql-server-tcp-ip-port-being-used/) 2. Enable firewall for the port you've found 3. Change Data Source in connection string to: "host.docker.internal," – Grzegorz Pasnik Jun 16 '18 at 14:05
  • 2
    Just wasted 2 hours on this connection issue, just to realize I forgot to restart the SQL Server service all this time ;( So glad I ran into this answer – Shay Jan 18 '20 at 00:36
  • Also check if the windows service SQL Server Browser is started – Francesco B. May 31 '23 at 16:08
  • And use the connection string with host.docker.internal\\mssqlserver,1433 – Francesco B. May 31 '23 at 16:10