在UNIX框中执行bcp时获得错误

时间:2022-11-20 21:55:22

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.

目前,我正在Unix box中执行Perl脚本。Perl脚本内部使用BCP命令从MS-SQL DB获取数据。相同的perl脚本在Windows中正常运行。但是当我在Unix中执行它时(使用Putty)。它在控制台显示以下错误消息。

sh: bcp: command not found

Below is my sql command in perl script.

下面是我在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";

I am successfully able to connect with the DB.

我成功地连接了数据库。

I need your help to resolve above bcp issue.

我需要你的帮助来解决bcp问题。

3 个解决方案

#1


2  

On unix, there is a bcp tool for sybase clients. It works only for Sybase Products.

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

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.

使用MSSQL服务器的bcp有一个开源的替代方案:freebcp,但是freetds库有点难于配置,而且(作为志愿者的逆向工程)它只对相对简单的数据类型有效。

To install it on ubuntu/debian based linux machines, run this

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

apt-cache search freetds

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

This command is optional:

这个命令是可选的:

apt-file list freetds-bin

apt-file 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

These commands install most of what you need

这些命令安装了您所需的大部分内容

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

You must then enter your connection data into configfile

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

/etc/freetds/freetds.conf

[OurMSSQLServer]

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

Maybe something else in this configfile has to be changed. This I don't remember right now.

也许这个configfile中的其他东西必须被修改。这个我现在不记得了。

From here on you are on your own. Please read the freetds docs: http://www.freetds.org/userguide/

从这里开始,你要靠自己。请阅读freetds文档:http://www.freetds.org/userguide/

The freetds software is up-to-date (actively developed). But the dev team is very small I think.

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

You can also compile freetds from source, but that may take more effort.

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

#2


1  

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

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

#3


0  

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

你可以得到从Perl编程访问该数据库在unix上使用DBI‌→DBD::ODBC‌→Easysoft SQL Server ODBC驱动程序

#1


2  

On unix, there is a bcp tool for sybase clients. It works only for Sybase Products.

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

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.

使用MSSQL服务器的bcp有一个开源的替代方案:freebcp,但是freetds库有点难于配置,而且(作为志愿者的逆向工程)它只对相对简单的数据类型有效。

To install it on ubuntu/debian based linux machines, run this

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

apt-cache search freetds

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

This command is optional:

这个命令是可选的:

apt-file list freetds-bin

apt-file 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

These commands install most of what you need

这些命令安装了您所需的大部分内容

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

You must then enter your connection data into configfile

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

/etc/freetds/freetds.conf

[OurMSSQLServer]

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

Maybe something else in this configfile has to be changed. This I don't remember right now.

也许这个configfile中的其他东西必须被修改。这个我现在不记得了。

From here on you are on your own. Please read the freetds docs: http://www.freetds.org/userguide/

从这里开始,你要靠自己。请阅读freetds文档:http://www.freetds.org/userguide/

The freetds software is up-to-date (actively developed). But the dev team is very small I think.

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

You can also compile freetds from source, but that may take more effort.

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

#2


1  

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

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

#3


0  

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

你可以得到从Perl编程访问该数据库在unix上使用DBI‌→DBD::ODBC‌→Easysoft SQL Server ODBC驱动程序