在UNIX框中执行bcp时出错

时间:2012-02-07 13:24:30

标签: linux perl 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问题。

3 个答案:

答案 0 :(得分:2)

在unix上,有一个用于sybase客户端的bcp工具。它仅适用于Sybase产品。

对于与MSSQL服务器一起使用的bcp有一个开源替代品:freebcp但是freetds库有点难以配置,并且(由志愿者进行逆向工程)它只能在相对简单的情况下工作数据类型。

要在基于ubuntu / debian的linux机器上安装它,请运行此

  

apt-cache搜索freetds

freetds-common - configuration files for FreeTDS SQL client libraries
freetds-dev - MS SQL and Sybase client library (static libs and headers)
libct4 - libraries for connecting to MS SQL and Sybase SQL servers
libdbd-freetds - Freetds database server driver for libdbi
libsybdb5 - libraries for connecting to MS SQL and Sybase SQL servers
tdsodbc - ODBC driver for connecting to MS SQL and Sybase SQL servers
freetds-bin - FreeTDS command-line utilities
libaprutil1-dbd-freetds - Apache Portable Runtime Utility Library - FreeTDS Driver
sqsh - commandline SQL client for MS SQL and Sybase servers
libqt4-sql-tds - Qt 4 FreeTDS database driver

此命令是可选的:

  

apt-file list freetds-bin

freetds-bin: /usr/bin/bsqldb
freetds-bin: /usr/bin/bsqlodbc
freetds-bin: /usr/bin/datacopy
freetds-bin: /usr/bin/defncopy
freetds-bin: /usr/bin/fisql
freetds-bin: /usr/bin/freebcp
freetds-bin: /usr/bin/osql
freetds-bin: /usr/bin/tdspool
freetds-bin: /usr/bin/tsql

这些命令会安装您需要的大部分内容

apt-get install freetds-bin 
apt-get install freetds-dev 

然后必须将您的连接数据输入configfile

/etc/freetds/freetds.conf

[OurMSSQLServer]

    host = 1xx.xxx.xxx.xx
    port = 1433
    tds version = 8.0

可能必须更改此配置文件中的其他内容。我现在不记得了。

从这里开始,你就是靠自己。请阅读freetds docs:http://www.freetds.org/userguide/

freetds软件是最新的(积极开发)。但我认为开发团队规模很小。

您也可以从源代码编译freetds,但这可能需要更多的努力。

答案 1 :(得分:1)

错误非常明确:在$ PATH中找不到bcp命令,因此它失败了,但真正的问题是bcp是一个MS SQL服务器实用程序,你在UNIX上找不到它

答案 2 :(得分:0)

您可以使用DBIDBD::ODBCEasysoft SQL Server ODBC Driver

从unix上的Perl编程访问MSSQL数据库
相关问题