Take the 2-minute tour ×
Server Fault is a question and answer site for professional 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
    
Cross-posted question from SO, has some good responses already for the problem: stackoverflow.com/questions/5083189/… –  Shawn Melton Nov 13 '12 at 16:09
add comment

1 Answer

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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