简体   繁体   中英

sqlcmd login failed when connecting SQL Server from Ubuntu

SQL Server 2016 is installed on windows server 2012 R2 server "dev" and sql server service is listening to all IP on port 1433. I can use sqlcmd to connect to it both from local and another remote windows server 2012. the command is simple: sqlcmd -S dev\\INSTACE -d database -U test1 -P test1

However, when I try to connect from a Ubuntu 16.04 machine using same command, I always got following error:

    Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : TCP Provider: Error code 0x2AF9.
Sqlcmd: Error: Microsoft ODBC Driver 13 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..

I can also use telnet from Ubuntu server to connect port 1433. (telnet dev 1433).

appreciate for hint or helps.

BTW, I'm not using freetds but OOTB Microsoft ODBC driver for Ubuntu 16.04.

one more: just tested with jdbc and SQL server can be connected from Ubuntu using jdbc.

Finally, this issue is solved by: 1) enable TCP/IP on every IP addresses on SQL server side. It's not enough to enable "IPAll" but every TCP/IP address, including IPV4 and IPV6. 2) it seems like you can't give instance name in command. Default instance can be connected in this case. I haven't figured out how to handle instance name other than default instance. 3) In windows, you don't need quote to wrap password but you need it in Ubuntu. like: "sqlcmd -S dev\\MyInstance -U sa -P abcd!efg" works on Windows but not on Ubuntu. In Ubuntu, I have to do like: "sqlcmd -S dev -U sa -P 'abcd!efg'

The correct command is:

sqlcmd -S dev\\\Instance,1433 -U test1 -P test1

It is by design, if you use a named instance, then you need to provide the port number even it is default port, and the double back slash \\\\ is also a must. Reference: https://github.com/Microsoft/msphpsql/issues/442

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM