Search code examples
sql-servercygwinsqlcmd

Connect to SQL Server from cygwin window times out, from DOS prompt works


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