5

The Platform and Software versions I am using are as follows :

Red Hat Enterprise Linux Server release 7.4 (Maipo)
Microsoft SQL Server 2017 (RTM-CU3-GDR) (KB4052987) - 14.0.3015.40 (X64) 
Dec 22 2017 16:13:22 
Copyright (C) 2017 Microsoft Corporation Express Edition (64-bit) on
Windows Server 2012 R2 Standard 6.3 <X64> (Build 9600:) (Hypervisor)

I have searched a lot for answers on Google but haven't found any solution yet. I can't connect to RDS instance having MS SQL instance via Linux.

It shows following errors If I try to :

[ec2-user@ip-~]$ sqlcmd -H mssqldb.xxxxxxxxxxxxxx.com -P 1433
                        -U userXXXXX -P aXXXXXX
                        -Q 'SELECT TOP 1 [n] FROM [dbbase2].[dbo].[table_people]'

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server :
               Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server :
               TCP Provider: Error code 0x2749.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server :
               A network-related or instance-specific error has occurred while
               establishing a connection to SQL Server. The 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.

[ec2-user@ip- ~]$  Check if instance name is correct and if SQL Server is
                   configured to allow remote connections.

Could anyone please tell the issue and resolution ?

Thanks.

8
  • @PimpJuiceIT I tried to run: sqlcmd -S EC2XXXXXXXX -d dbXXXX -P 1433 -U userXXXXX -P aXXXXX -Q 'SELECT SELECT TOP 1 [n] FROM [Nums]' or: sqlcmd -S EC2XXXXXXXX -d dbXXXX -P 1433 -U userXXXXX -P aXXXXX Is the same error. I have got only a connection by SQL Server Management Studio from Windows 7 but there is a still a problem when I would like to connect through Linux. Mar 18, 2018 at 13:30
  • @PimpJuiceIT I suspect but I'm not sure that maybe it is a problem with SQL Server Configuration Manager where I should set up TCP/IP protocols but I don't have access to this tool. Mar 18, 2018 at 13:45
  • What I checked in Linux { I first run commands: sudo yum check-update and sudo yum update mssql-toolsthen I run: sqlcmd -S EC2XXXX-SERVERNAME\INSTANCE,1433 [ec2-user@ip-1 ~]$ sqlcmd -S EC2XXXX-SERVERNAME\INSTANCE,1433 Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired. Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2AF9. Mar 18, 2018 at 17:59
  • In Windows this works and port is open every time: {telnet instance.XX..rds.amazonaws.com 1433}When I am checking telnet in Linux I see after a few seconds:{Trying 1XX.XX.XXX.XXX...Connected to INSTANCE.X.rds.amazonaws.com.Escape character is '^]'.Connection closed by foreign host. } Mar 18, 2018 at 17:59
  • What do you mean about the specific version of the SQL Server instance? What is the quickest way to remove 17 ver drivers and install ODBC drivers 16 or 15? Mar 18, 2018 at 19:44

3 Answers 3

2

I got the same error. It was because I used -H mssqlserver instead of -S mysqlserver

This worked for me

sqlcmd -U sa -S mssqlserver -P secret

In the question the -P option is used for port and password, but it is only supported for the password.

If e port different from 1433 should be used, then pass it with the host name

sqlcmd -U sa -S mssqlserver,1444 -P secret

sqlcmd Install instructions can be found in https://docs.microsoft.com/en-us/sql/tools/sqlcmd-utility?view=sql-server-ver15

In case anybody cares about Emacs Org-babel

#+HEADER: :results table :engine mssql :dbhost mssqlserver :database master :dbuser sa :dbpassword secret
#+begin_src sql
SELECT name, database_id, create_date
FROM sys.databases;
#+end_src

Found in

0

Check

telnet mssqldb.xxxxxxxxxxxxxx.com 1433 

should open connection to the port.

make sure default instance exists (not named instance) otherwise provide the instance name in the command.

0

For me it was using a different port 1434.
And I had to append it to the servername in the connectionstring using a comma:

sqlcmd -S SERVERNAME,1434 -U sa -P 'MySecret'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .