Connect to SQL Server from cygwin timeout, from DOS command prompt

I can connect to my SQL Server database via sqlcmd from a DOS command prompt window, but not from a Cygwin window. From DOS:

F:\Cygnus>sqlcmd -Q "select 'a test'" -S .\SQLEXPRESS 

test

(1 row affected)

 F:\Cygnus> 

==================================================== ==

From Cygwin:

 $ sqlcmd -Q "select 'a test'" -S .\SQLEXPRESS 

HResult 0x35, Level 16, State 1
Named Pipe Provider: Failed to open a connection to SQL Server [53]. Sqlcmd: error: Microsoft SQL Native client: An error occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that at default settings SQL Server does not allow remote connections .. Sqlcmd: error: Microsoft SQL native client: Login timed out.

+4
source share
3 answers

The backslash is eaten by the cygwin bash shell. Try to double it:

 sqlcmd -Q "select 'a test'" -S .\\SQLEXPRESS 
+8
source

You may need to allow remote connections for this and provide the fully qualified server name. SERVER \ SQLEXPRESS

0
source

You can also pass the request / command to db and get the output in the shell if you use the "-Q" switch:

 sqlcmd -Q "select * from nice.dbo.TableName ac ORDER BY 1 DESC" -S server_name\\db_name 
0
source

Source: https://habr.com/ru/post/1276998/


All Articles