Perl dbi:Sybase连接到使用来自Linux机器的Windows身份验证的SQL Server

时间:2018-08-31 07:15:10

标签: sql-server perl dbi

我正在使用perl DBI从Linux机器上使用dbi:Sybase连接到SQL Server,但是当我尝试连接时,却出现了类似

的错误

DBI connect('DBName','DOMAIN\UserName',...) failed: Server message number=18452 severity=14 state=1 line=1 server=SERVERNAME text=Login failed. The login is from an untrusted domain and cannot be used with Windows authentication. OpenClient message: LAYER = (0) ORIGIN = (0) SEVERITY = (78) NUMBER = (34) Server DATAMART, database Message String: Adaptive Server connection failed at connect.pl line 37

我的代码是:

BEGIN{
   $ENV{SYBASE} = "/opt/sybclient-12.5.1";
   $ENV{FREETDSCONF} = "PATH/config/freetds.conf";
}

use lib "PATH/perl-lib/lib64/perl5";
use lib "PATH/perl-lib/share/perl5/";


my $lib = "PATH/FreeTDS_32bit/libct.so.4.0.0";
DynaLoader::dl_load_file($lib, 1) or die "Unable to load freetds libct.so: $!\n";

$host = 'ServerName';  $port = 'PORT';
$database = 'DBName';  $user = 'DOMAIN\\userName'; 
$auth = 'PASS';

$_dmDBH = DBI->connect(dbi:Sybase:server=$host; database=$database;port=$port","$user", "$auth") || die "Database connection not made: $DBI::errstr";

1 个答案:

答案 0 :(得分:0)

我能够使用freeTds解决此问题,在freeTds配置文件中,我们需要将ntlmv2设置为yes

[PACKAGE-NAME]
        host = <HOSTANME>
        database = <DB-Name>
        tds version = 8.0
        use ntlmv2 = yes
        client charset = UTF-8