在 UNIX 机器中执行 bcp 时出现错误
目前我正在 Unix 机器上执行 Perl 脚本。 Perl 脚本内部使用 BCP 命令从 MS-SQL DB 获取数据。相同的 perl 脚本在 Windows 中正确运行。但是当我在 Unix 中执行它时(使用 Putty)。它在控制台上显示以下错误消息。
sh: bcp: command not found
下面是我在 perl 脚本中的 sql 命令。
"bcp \"select drive_id, ilf, xcoord, ycoord
from $mdtdb\.dbo\.$mdtcentraldtdtable a where
drive_id = $driveid and not exists
(select 'x' from $mdtdb\.dbo\.$mdtcentralaudittable b where
a.drive_id = b.drive_id and a.ilf = b.ilf)\"
queryout $tempdatafile -o $bcpoutfile -S $mdtsvr -q -c -t ,
-U $user1 -P $pw1";
我能够成功连接数据库。
我需要您的帮助来解决上述 bcp 问题。
Currently I am working on executing Perl script in Unix box. The Perl script internally uses BCP command for for fetching the data from MS-SQL DB. The same perl script is properly running in Windows. But when I am executing it into Unix (using Putty). It is showing following error message on console.
sh: bcp: command not found
Below is my sql command in perl script.
"bcp \"select drive_id, ilf, xcoord, ycoord
from $mdtdb\.dbo\.$mdtcentraldtdtable a where
drive_id = $driveid and not exists
(select 'x' from $mdtdb\.dbo\.$mdtcentralaudittable b where
a.drive_id = b.drive_id and a.ilf = b.ilf)\"
queryout $tempdatafile -o $bcpoutfile -S $mdtsvr -q -c -t ,
-U $user1 -P $pw1";
I am successfully able to connect with the DB.
I need your help to resolve above bcp issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在unix上,有一个用于sybase客户端的bcp工具。它仅适用于 Sybase 产品。
有一个与 MSSQL 服务器一起使用的 bcp 的开源替代品: freebcp 但是 freetds库的配置有点困难,并且(这是志愿者的逆向工程工作)它仅适用于相对简单的数据类型。
要在基于 ubuntu/debian 的 Linux 机器上安装它,请运行此命令
该命令是可选的:
这些命令安装您需要的大部分内容
然后您必须将连接数据输入到配置文件中
也许此配置文件中的其他内容必须更改。这个我现在不记得了。
从现在开始,你就只能靠自己了。请阅读 freetds 文档: http://www.freetds.org/userguide/
freetds 软件是最新的(积极开发的)。但我认为开发团队很小。
您还可以从源代码编译 freetds,但这可能需要更多的努力。
On unix, there is a bcp tool for sybase clients. It works only for Sybase Products.
There is an open-source replacement for bcp that works with MSSQL server: freebcp But the freetds library is a bit difficult to configure, and (being a reverse engineering effort by volunteers) it works only with relatively simple datatypes.
To install it on ubuntu/debian based linux machines, run this
This command is optional:
These commands install most of what you need
You must then enter your connection data into configfile
Maybe something else in this configfile has to be changed. This I don't remember right now.
From here on you are on your own. Please read the freetds docs: http://www.freetds.org/userguide/
The freetds software is up-to-date (actively developed). But the dev team is very small I think.
You can also compile freetds from source, but that may take more effort.
错误非常明显:在您的 $PATH 中找不到 bcp 命令,因此它失败,但真正的问题是 bcp 是一个 MS SQL Server 实用程序,您在 UNIX 上找不到它
The error is very clear: the bcp command is not found in your $PATH and therefore it fails, but the real issue is that bcp is a MS SQL server utility and you won't find it on UNIX
您可以使用 DBI → DBD::ODBC → Easysoft SQL Server ODBC 驱动程序
You might be able to get programmatic access to an MSSQL database from Perl on unix by using DBI → DBD::ODBC → Easysoft SQL Server ODBC Driver