Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm trying to use sqlcmd to execute some SQL scripts.

Using a test command with a simple query like:

sqlcmd -S HOSTNAME -d MYDATABASE -Q 'SELECT Names FROM Customers'

sqlcmd does not appear to make any attempt to connect to the server as it displays this message:

Sqlcmd: Error: Connection failure.

SQL Native Client is not installed correctly. To correct this, run SQL Server Setup.`

The native client was presumably installed as part of the SQL Server setup and likely correctly. I actually get this message on any machine with SQL server installed trying to use sqlcmd so it's not a matter of the installation being corrupt.

Unfortunately the message really tells me nothing about the problem so I don't know what the real issue is. I know the SQL Native client is working properly since a vbscript was able to execute SQL queries against the database.

Is there some additional configuration needed to use sqlcmd?

share|improve this question

closed as off-topic by Mark Henderson Jun 15 at 0:40

  • This question does not appear to be about server, networking, or related infrastructure administration within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

Cross-posted question from SO, has some good responses already for the problem:… –  Shawn Melton Nov 13 '12 at 16:09
This question has a cross-posted duplicate that is answered at… –  Mark Henderson Jun 15 at 0:40

1 Answer 1

I have the feeling that your connection error is a firewall issue on the server. In the Windows Firewall on the server computer, please make sure that TCP port 1433 (or whichever you chose) is open for incoming connections. If you prefer you could also constrain rule for the SQL server service, that is \MSSQL\Binn\sqlservr.exe.

The port is not opened by the installation procedure nor is there a predefined rule. If you use dynamic ports you would also have to open UDP port 1434 for the SQL server browser.

With the proper firewall adjustments you should be able to connect. I also want to mention that in my installation (SQL server 2012) I had to use double quotes for the query; single quotes resulted in a nasty error message like "unexpected argument".

sqlcmd -S HOSTNAME -d MYDATABASE -Q "SELECT Names FROM Customers"
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.