简体   繁体   English

在unix上使用perl和freetds访问mssql数据库时遇到麻烦

[英]trouble accessing mssql db using perl and freetds on unix

I'm trying to connect to a MS-SQL Database using perl and freetds. 我正在尝试使用perl和freetds连接到MS-SQL数据库。 I have tested the installation of freetds using the unix commandline 我已经使用unix命令行测试了freetds的安装

`/usr/local/exec/bin/tsql -S myDB -I freetds.conf -U userName -P passw0rd -D DataBase1 -o q < query.sql` 

where query.sql contains my sql query. 其中query.sql包含我的sql查询。 It runs perfectly well. 它运行得很好。 But when I try the same with perl it gives me the following error - 但是当我用perl尝试同样的操作时,出现以下错误-

`Your sybase home directory is /opt/sybase. Check the environment variable SYBASE if it is not the one you want! Cannot access file /opt/sybase/config/objectid.dat` 

but running 但是跑步

$ set | grep SYBASE $ set | grep SYBASE yields SYBASE=/usr/fsf/freetds $ set | grep SYBASE产生SYBASE=/usr/fsf/freetds

Below is my perl code: 下面是我的perl代码:

#!/usr/bin/perl5/core/5.8.8/exec/bin/perl

use lib qw(/usr/perl5/core/5.8.8/exec/lib);
use lib qw(/usr/perl5/DBI/1.607/exec/5.8/lib/perl5);
use lib qw(/usr/perl5/DBD-Sybase/1.09/exec/5.8/lib/perl5);

use DBI;
use DBD::Sybase;

my $user   = "userName";
my $passwd = "passw0rd";
my $server = "myDB";

`export SYBASE=/usr/fsf/freetds`;
`export LD_LIBRARY_PATH=/usr/fsf/freetds/0.82/exec/lib`;
`export FREETDSCONF=./freetds.conf`;

my $dbh = DBI->connect("DBD:Sybase:server=$server", $user, $passwd, {PrintError => 0});

unless ($dbh) {
    die "ERROR: Failed to connect to server ($server).\nERROR MESSAGE: $DBI::errstr";
} 
else {
    print "\n";
    print "Successful Connection.";
}

Any help much appreciated! 任何帮助,不胜感激!

The path to your drivers says 5.10. 驱动程序的路径为5.10。 You might have downloaded the drivers for the wrong version of perl. 您可能为错误版本的perl下载了驱动程序。 Either update to 5.10.1 or get the drivers for 5.8.8. 更新到5.10.1或获取5.8.8的驱动程序。

I have figured it out. 我已经知道了。 Well, you need to first set the SYBASE environment variable before you install DBD-Sybase. 好了,您需要在安装DBD-Sybase之前先设置SYBASE环境变量。 And that's the reason behind Your sybase home directory is /opt/sybase when it is supposed to point to the freetds installation location. 这就是当Your sybase home directory is /opt/sybase应该指向freetds安装位置时,其原因Your sybase home directory is /opt/sybase Ref: http://www.idevelopment.info/data/SQLServer/DBA_tips/Programming/PROG_4.shtml#Install%20DBD-Sybase 参考: http : //www.idevelopment.info/data/SQLServer/DBA_tips/Programming/PROG_4.shtml#Install%20DBD-Sybase

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM