I'm trying to connect to a SQL Server instance from WSL2 (Arch Linux) with this command:
sqlcmd -S tcp:XX.XXX.XXX.XX\\stix -U service_stix -C
But I get:
Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : Login timeout expired. Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : MAX_PROVS: Error Locating Server/Instance Specified [xFFFFFFFF]. . Sqlcmd: Error: Microsoft ODBC Driver 18 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..
If try: nc -zv XX.XXX.XXX.XX 1433
, I get: Connection to XX.XXX.XXX.XX 1433 port [tcp/ms-sql-s] succeeded!
, and also:
➜ ~ telnet XX.XXX.XXX.XX 1433
Trying XX.XXX.XXX.XX...
Connected to XX.XXX.XXX.XX.
Escape character is '^]'.
In PowerShell: Test-NetConnection -ComputerName "XX.XXX.XXX.XX" -Port 1433
, which yields:
ComputerName : XX.XXX.XXX.XX
RemoteAddress : XX.XXX.XXX.XX
RemotePort : 1433
InterfaceAlias : vnet-site2site
SourceAddress : 172.SS.SS.S
TcpTestSucceeded : True
Issuing the same command: sqlcmd -S tcp:XX.XXX.XXX.XX\stix -U my_user -C
in CMD/PowerShell, I`m able to connect to the instance:
PS C:\Users\Windows11> sqlcmd -S tcp:XX.XXX.XXX.XX\stix -U my_user -C
Password:
1>
Is it possible to connect to an SQL Server instance in WSL2, using a VPN?
SQL Browser service is definitely running, as I've said, I can access the database from Wndows with CMD (with SQLCMD) and a NodeJS application (like Prisma).
I think that I'm missing some configuration on Windows or WSL2 part.
One problem though: I can't access the database nor it's server directly to configure something specific, I would have to ask the DBA.
To add context:
I'm trying to connect a NodeJS application (without Docker) within WSL2 (Arch Linux) with the following connection string structure:
DATABASE_URL=sqlserver://XX.XXX.XXX.XX\stix:1433;database=my-database;user=my_user;password=my_pass;integratedSecurity=false;trustServerCertificate=true;
But I receive an error from my healthcheck endpoint (using Prisma to make a simple query):
Invalid
prisma.$queryRaw()
invocation:Error querying the database: Conversion error: SQL browser timeout during resolving instance stix. Please check if browser is running in port 1433 and does the instance exist.
nc
(from WSL2) andTest-NetConnection
(from PowerShell), but thesqlcmd
only fails in WSL2. It's been far too long since I've used SQL Server to be of much use if it's something unique there. But I do so in the doc thatsqlcmd -S tcp:172.x.x.x,1433
is an option. Any difference with that?Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : Login failed for user 'my_user'..
, but it's the same thing for CMD/PS, changing to:sqlcmd -S tcp:10.187.114.20\stix -U service_stix -C
(w/wotcp
prefix), works as expected, trying this in WSL2 gives me the error described after "But I get..." in my question.XX.XXX.XXX.XX\\my_instance
, removing escape gives:Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : TCP Provider: Error code 0x2AF9.
naturallywsl --export/--import
a new version as WSL1. See the bottom of this answer for details on the conversion.