SQL sqlcmd 无法运行 - 这是配置问题吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5083189/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 09:24:50  来源:igfitidea点击:

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

sqlsql-servertsqlsqlcmd

提问by nuit9

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

我正在尝试使用 sqlcmd 来执行一些 SQL 脚本。

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 似乎没有尝试连接到服务器,因为它显示以下消息:

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

Sqlcmd:错误:连接失败。
SQL Native Client 安装不正确。若要更正此问题,请运行 SQL Server 安装程序。

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.

本机客户端可能是作为 SQL Server 安装程序的一部分安装的,并且很可能是正确的。我实际上在任何安装了 SQL Server 的机器上都收到了这条消息,试图使用 sqlcmd 所以这不是安装损坏的问题。

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.

不幸的是,该消息确实没有告诉我有关问题的任何信息,所以我不知道真正的问题是什么。我知道 SQL Native 客户端工作正常,因为 vbscript 能够对数据库执行 SQL 查询。

Is there some additional configuration needed to use sqlcmd?

使用 sqlcmd 是否需要一些额外的配置?

回答by The HomusOnline

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:

我有同样的错误。经过大量搜索和重新安装后,我检查了我的 PATH 是否有无关的东西。由于我使用的软件已经通过 MSDE、2005 Express 和现在的 2008 Express R2,我的 PATH 语句有以下条目:

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\

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.

我删除了 80 和 90 条目并停止接收错误。我进行了测试,安装 2005 Express 仍然没有问题地响应 SQLCMD 条目。

回答by huongsonngochung

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

我在运行命令时遇到了这个错误sqlcmd。为了解决这个问题,我删除了PATH环境变量中不必要的部分,并插入了以下内容:

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

This PATH is for SQL Server 2012

此 PATH 适用于 SQL Server 2012

回答by Rachel

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

我也遇到了MS SQL Server 2014 的这个错误。

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

Sqlcmd:错误:连接失败。SQL Native Client 安装不正确。若要更正此问题,请运行 SQL Server 安装程序。

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

首先,确认安装了SQL Server Native Client。按照MSDN 的规定, bcp.exe 和SQLCMD.exe文件应位于以下目录中。

<Install Directory>\Client SDK\ODBC0\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

如果文件不存在,您可以从Microsoft 下载中心使用ENU\x86\sqlncli.msi 或 ENU\x64\sqlncli.msi下载并安装客户端。MSSQL 2014 使用 2012 客户端

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

完成此操作后,您应该可以毫无问题地使用 SQLCMD。

Path environment variable on my machine contains the following entries:

我机器上的路径环境变量包含以下条目:

C:\Program Files\Microsoft SQL Server\Client SDK\ODBC0\Tools\Binn
C:\Program Files (x86)\Microsoft SQL Server0\Tools\Binn\ManagementStudio\
C:\Program Files (x86)\Microsoft SQL Server0\DTS\Binn\
C:\Program Files (x86)\Microsoft SQL Server0\Tools\Binn\

回答by RichardTheKiwi

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

我知道 SQL Native 客户端工作正常,因为 vbscript 能够对数据库执行 SQL 查询。

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

不,你没有。您只知道某些客户端可以工作,但不一定是 SQL Native 客户端。

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

条条大路通罗马http://www.connectionstrings.com/sql-server-2008(查看Provider列表),却有一个被堵死了。

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

只需从控制面板执行修复/修改设置,或安装另一个实例(确保安装了 Native 客户端),然后再次删除它。