通过Perl连接到Teradata

时间:2011-06-29 17:27:19

标签: sql perl odbc teradata dbd

有人有过这方面的成功吗?网上没有大量的参考资料,我已经用尽了谷歌上的所有相关结果。这是我的剧本:

#!/usr/bin/perl

use DBI;
use DBD::ODBC;

$user = "user";
$pw = "pw";
$ip = "192.168.1.0"

#DBI->trace(DBD::ODBC->parse_trace_flags('odbconnection'));

#my $connect_attrs = { PrintError => 0, RaiseError => 1, AutoCommit => 1 };

my $dbh = DBI->connect("dbi:ODBC:$ip", $user, $pw);

错误消息:

DBI connect('192.168.1.0','user',...) failed: (no error string) at ./teradata.pl line 13

注释掉的两行是我之前无法尝试连接数据库的遗留问题。

更新:以前是我使用DBD模块所做的努力。

#!/usr/bin/perl

use DBI;

$user = "xxxx";
$pw = "xxxx";

my $dbh = DBI->connect("dbi:Teradata:tdsn", $user, $pw);

错误:

DBI connect('tdsn','xxxx',...) failed: Unable to get host address. at ./teradata.pl line 12

第二次尝试:

#!/usr/bin/perl

use DBI;

$user = "xxxx";
$pw = "xxxx";

my $dbh = DBI->connect("dbi:Teradata:192.168.1.0", $user, $pw);

错误:

DBI connect('192.168.1.0','xxxx',...) failed: Deprecated logons are not allowed by administrator.  Upgrade client software to latest version. at ./teradata.pl line 12

第三...

#!/usr/bin/perl

use DBI;
use DBD::ODBC;

$user = "xxxx";
$pw = "xxxx";

my $dbh = DBI->connect("dbi:ODBC:tdsn", $user, $pw);

.odbc.ini的

[ODBC]
InstallDir              = /usr/odbc
Trace           = 0
TraceDll                = /usr/odbc/lib/odbctrac.so
TraceFile               = /home/xxxx/odbctrace.log
TraceAutoStop           = 0

[ODBC Data Sources]
default         = tdata.so
testdsn         = tdata.so

[default]
Driver          = /usr/odbc/drivers/tdata.so
Description             = Default DSN is Teradata 5100
DBCName         = **ip_addr**
LastUser                = DLPStats
Username                = xxxx
Password                = xxxx
Database                = MSS_TEMP
DefaultDatabase         = MSS_TEMP

[tdsn]
Driver=/usr/odbc/drivers/tdata.so
Description=Teradata running Teradata V1R5.2
DBCName=**ip_addr**
LastUser=
Username=xxxx
Password=xxxx
Database=
DefaultDatabase=

错误:

DBI connect('tdsn','xxxx',...) failed: (no error string) at ./teradata.pl line 13

ODBCINST.INI

[ODBC DRIVERS]
Teradata=Installed

[Teradata]
Driver=/usr/odbc/drivers/tdata.so
APILevel=CORE
ConnectFunctions=YYY
DriverODBCVer=3.51
SQLLevel=1

3 个答案:

答案 0 :(得分:4)

您需要下载并安装Teradata DBD模块。

答案 1 :(得分:1)

$ ip不能是IP地址。它必须是ODBC驱动程序管理器已知的ODBC数据源的名称。我们需要了解您的司机经理以进一步提供帮助。假设它是unixODBC,你将有一个odbcinst.ini文件,teradata驱动程序需要用指向驱动程序共享对象的行命名。然后在odbc.ini文件中创建一个数据源。

答案 2 :(得分:0)

我很确定您已经找到了答案,但是我还是要贴出来,以防其他人需要它:

odbcinst.ini:

[Teradata Database ODBC Driver 16.20]
Description=Teradata Database ODBC Driver 16.20
Driver=/opt/teradata/client/16.20/odbc_64/lib/tdataodbc_sb64.so
# Note: Currently, Data Direct Driver Manager does not support Connection Pooling feature.
CPTimeout=60

odbc.ini:

[ODBC Data Sources]
16.10=Teradata Database ODBC Driver 16.20
15.10=Teradata Database ODBC Driver 16.20
13.00=Teradata Database ODBC Driver 16.20
13.10=Teradata Database ODBC Driver 16.20
14.00=Teradata Database ODBC Driver 16.20

请注意数据源的名称可以是任何东西,在这种情况下,我选择了版本。

Perl代码:

use DBD::ODBC;

my $conn = DBI->connect("DBI:ODBC:14.00",$username,$password);
#note how I'm connecting to the data source 14.00

my $create_user = $conn->prepare("CREATE USER $db_user from $username as perm = $perm, 
                                                password = XXXXXX,
                                                spool = $spool,
                                                NO fallback protection,
                                                default database = $db_user,
                                                NO after journal");
my $status = $create_user->execute();
$conn->disconnect();