'Connect local SQL Server from WSL2 (Ubuntu) [duplicate]
I started to develop a .NET Core Web API application with SQL Server. I use the Windows Subsystem for Linux (I store the files in the Ubuntu server).
Unfortunately I can't connect to SQL Server which is installed on Windows 10.
I enabled TCP/IP in SQL Server configuration but I don't know which is the correct connection string.
Solution 1:[1]
There is long issue that windows services are not accessible from WSL - github
Making long story short, you need to use IP address of your windows machine as server.
You can take it multiple ways e.g. calling this command from Windows commandline
ipconfig /all
and taking your IP address.
You need to enable 1433 port to be accessible from WSL in Windows Defender:
netsh advfirewall firewall add rule name=WSL_SQL dir=in protocol=tcp action=allow localport=1433 remoteip=localsubnet profile=any
Over here there is an issue. Opening concrete port works for me.
From your WSL terminal you can verify that you can access sql using e.g. telnet.
telnet <windows_host_ip> 1433
It should return something like this:
Trying <windows_host_ip>...
Connected to <windows_host_ip>.
Escape character is '^]'.
If it doesn't work please also verify that you have TCP service enabled in you SQL Configuration Manager
-> here you can find guidance for it -> link
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | wolszakp |