Connect to SQL Server from cygwin window times out, from DOS prompt works
-
02-07-2019 - |
Question
I can connect to my SQL Server database via sqlcmd from a DOS command window, but not from a Cygwin window. From DOS:
F:\Cygnus>sqlcmd -Q "select 'a test'" -S .\SQLEXPRESS
a test
(1 rows affected)
F:\Cygnus>
====================================================
From Cygwin:
$ sqlcmd -Q "select 'a test'" -S .\SQLEXPRESS
HResult 0x35, Level 16, State 1
Named Pipes Provider: Could not open a connection to SQL Server [53]. Sqlcmd: Error: Microsoft SQL Native Client : An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.. Sqlcmd: Error: Microsoft SQL Native Client : Login timeout expired.
Solution
The backslash is being eaten by cygwin's bash shell. Try doubling it:
sqlcmd -Q "select 'a test'" -S .\\SQLEXPRESS
OTHER TIPS
You may have to allow remote connections for this, and give the full server name i.e SERVER\SQLEXPRESS
You can also pass query/instruction to db and receive output in shell if you use "-Q" switch:
sqlcmd -Q "select * from nice.dbo.TableName ac ORDER BY 1 DESC" -S server_name\\db_name