Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlcmd won't run - Is this a config issue?

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?

like image 806
nuit9 Avatar asked Feb 22 '11 19:02

nuit9


People also ask

How can I tell if SQLCMD is working?

You could try to execute sqlcmd.exe -? in a process in your C# app - if it works, then SQLCMD is present - if not, it'll tell you something like "file not found" or "command invalid" or something ....

How do I enable SQLCMD?

Enable SQLCMD Scripting by Default To turn SQLCMD scripting on by default, on the Tools menu select Options, expand Query Execution, and SQL Server, click the General page, and then check the By default open new queries in SQLCMD Mode box.

What driver does SQLCMD use?

The sqlcmd utility is available with the Microsoft ODBC Driver for SQL Server on Linux and macOS.

What is the purpose of using SQLCMD?

Running Transact-SQL script files using sqlcmd You can use sqlcmd to execute database script files. Script files are text files that contain a mix of Transact-SQL statements, sqlcmd commands, and scripting variables. For more information about how to script variables, see Use sqlcmd with Scripting Variables.


2 Answers

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.

like image 160
The HomusOnline Avatar answered Oct 10 '22 04:10

The HomusOnline


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

like image 29
huongsonngochung Avatar answered Oct 10 '22 05:10

huongsonngochung