7

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
nuit9
  • 1,633
  • 3
  • 14
  • 8
  • If you post code, XML or data samples, **please** highlight those lines in the text editor and click on the "code samples" button ( `{ }` ) on the editor toolbar to nicely format and syntax highlight it! – marc_s Feb 22 '11 at 19:59
  • This belongs on serverfault.com or superuser.com – Jim Garrison Feb 22 '11 at 20:18
  • @Jim Based on which criteria? http://stackoverflow.com/faq `"Computer enthusiasts and power users"`? I keep it on the basis of `# software tools commonly used by programmers` – RichardTheKiwi Feb 22 '11 at 20:21
  • I guess it's right on the edge. Usually questions about configuration are more appropriate on one of the other sites, but I can see the counter-argument too. I just tried to remove my close vote but it won't let me. – Jim Garrison Feb 23 '11 at 03:07
  • For future users, as long as MS keeps this up to date, this is a good reference for locations(https://msdn.microsoft.com/en-us/library/ms143547(v=sql.130).aspx). Change version according to the one needed and look under shared files. – DVJex Sep 16 '16 at 06:08

4 Answers4

16

I had the same error. After a lot of searching and reinstalling, I checked my PATH for something unrelated. As the software I work on has gone through MSDE, 2005 Express and now 2008 Express R2, my PATH statement had these entries:

c:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\

I removed the 80 and 90 entries and stopped receiving the error. I tested and the install of 2005 Express still responded to the SQLCMD entry without issues.

The HomusOnline
  • 161
  • 1
  • 4
  • 2
    I had the same problem after installing SQL Server 2012 and when I checked the PATH environment variable value I found that there were duplicate entries for Sql Server 2012(folder named 110) and Sql Server 2008(folder named 100). So SQLCMD was always being picked up from the Sql Server 2008 folder even though the native client installed was of Sql Server 2012 and I had uninstalled Sql Server 2008. Hence the error. I removed the entries having the folder "100" and it was all fine. Basically, MS needs to do a better job of cleaning up during Sql Server uninstallation! – Kumar Vaibhav Mar 19 '13 at 13:14
  • 1
    Thanks! I had the same thing with after installing SQL server 2012. I removed the "100" entry and left the "110" entry alone. Now it works :) – user952342 May 21 '13 at 10:56
3

I met this error when running the command sqlcmd. To solve this, I removed unnecessary parts of the PATH environment variable, and inserted the following:

C:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\

This PATH is for SQL Server 2012

1

I was also getting this error with MS SQL Server 2014.

Sqlcmd: Error: Connection failure. SQL Native Client is not installed correctly. To correct this, run SQL Server Setup.

First, confirm that SQL Server Native Client is installed. As specified on MSDN, the bcp.exe and SQLCMD.exe files should be located in the below directory.

<Install Directory>\Client SDK\ODBC\110\Tools\Binn

If the files are not there, you can download and install the the client from the Microsoft Download center, using either ENU\x86\sqlncli.msi or ENU\x64\sqlncli.msi. MSSQL 2014 uses the 2012 client

Once this is done, you should be able to use SQLCMD without issues.

Path environment variable on my machine contains the following entries:

C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn
C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\
C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\
C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\
Rachel
  • 1,722
  • 8
  • 29
  • 34
0

I know the SQL Native client is working properly since a vbscript was able to execute SQL queries against the database.

No you don't. You only know that SOME client works, but not necessarily the SQL Native client.

All roads lead to Rome http://www.connectionstrings.com/sql-server-2008 (check Provider list), but one happens to be blocked.

Just perform a repair/modify setup from Control Panel, or install another instance (making sure Native client is installed), then remove it again.

RichardTheKiwi
  • 105,798
  • 26
  • 196
  • 262
  • Well the tools that ship with SQL Server such as Management Studio depend on SQL Native Client and work properly so that suggests the client itself works. I have tried uninstalling and reinstalling the native client which has no effect. – nuit9 Feb 22 '11 at 21:11
  • @nuit9 SSMS does not actually use the SQL Native Client. It uses the sqlsrv32.dll ODBC driver to make the connection to an instance of SQL Server. Proof of this can be done by using ProcessExplorer and do a search for the two DLL files after you connect to an instance with SSMS. –  Nov 13 '12 at 16:15