Open
Description
- VSCode Version:
1.70.0
- Local OS Version:
Microsoft Windows [Version 10.0.19043.1826]
- Remote OS Version:
Ubuntu 20.04.4 LTS
- Remote Extension/Connection Type:
Containers
- Logs:
N/A
Steps to Reproduce:
-
clone the project & open with vscode
git clone https://github.com/doggy8088/devcontainer-dotnet-mssql-ipv6-issue.git code devcontainer-dotnet-mssql-ipv6-issue
-
Reopen in Container
-
Here is the
PORTS
info. -
Connect to
localhost
locally usingsqlcmd
sqlcmd -S localhost -U sa -P P@ssw0rd -Q "SELECT 1;"
It will result:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Named Pipes Provider: Could not open a connection to SQL Server [2]. . Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired. Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
-
Connect to
127.0.0.1
locally usingsqlcmd
sqlcmd -S 127.0.0.1 -U sa -P P@ssw0rd -Q "SELECT 1;"
It will run successfully.
----------- 1 (1 rows affected)
I really expected I can connect to the db
container using localhost
. It because the PORTS
shows that.
During few hours research, I realized that Windows use IPv6 by default. When VSCode use IPv4 to do the port forwarding, connect to localhost
will route to ::1
and it will failed.
Two suggestions:
-
Change the
Local Address
to show127.0.01:1433
on thePORTS
window. -
Port forwarding support
IPv6
.