开发者

Connecting to Teradata via Perl

开发者 https://www.devze.com 2023-03-16 12:06 出处:网络
Has anyone had any success with this? There aren\'t a great deal of references online and I\'ve exhausted every relevant result on Google. Here\'s my script:

Has anyone had any success with this? There aren't a great deal of references online and I've exhausted every relevant result on Google. Here's my script:

#!/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);

The error message:

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

The two lines that are commented out are leftover from my previous fruitless attempts to connect to the DB.

UPDATE: Here are the previous efforts I made with the DBD module.

#!/usr/bin/perl

use DBI;

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

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

Error:

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

Second Attempt:

#!/usr/bin/perl

use DBI;

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

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

Error:

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

Third...

#!/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  开发者_如何学C             = /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=

Error:

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


You'll need to download and install the Teradata DBD module.


$ip cannot be an IP address. It needs to be the name of an ODBC data source which is known to your ODBC driver manager. We'd need to know your driver manager to help further. Assuming it is unixODBC, you'll have an odbcinst.ini file the teradata driver needs to be named in with a line pointing to the driver shared object. Then in the odbc.ini file you create a data source.


I'm pretty sure you've already found the answer but I'm going to post it anyway in case somebody else needs it:

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

Note how the name of the data source can be anything, I chose the version in this case.

Perl code:

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号