Perl非常新。我遇到了试图让DBI与SQL Server 2008数据库通信的问题。Perl DBI SQL SERVER连接性问题
当我尝试使用ODBC或直接尝试连接到SQL Servereveb时,出现以下错误。
我是新来的Perl,有人可以帮助...感谢
install_driver(MSSQL)失败:无法找到对象的方法 “set_sql” 通过一揽子 “类:: DBI :: MSSQL” 位于C :/Perl/lib/DBD/MSSQL.pm线79.编译失败在(EVAL 19)C需要:/Perl/site/lib/DBI.pm:744线3
use strict;
use warnings;
use diagnostics;
use Class::DBI::Loader;
use DBI;
use File::Glob ':glob';
my $DBUserName = "*******";
my $DBPassword = "*******";
my $DBName = "dbi:MSSQL:uat-dbserver1";
my $dbh = "";
my $sqlStatement = "";
my $sqlCmd = "";
my @EasySetTableNames =();
$dbh = DBI->connect($DBName, $DBUserName, $DBPassword,
{ PrintError => 0, AutoCommit => 0})
|| die "Database connection creation failed: $DBI::errstr\n";
$sqlStatement = "SELECT * from tableA ";
$sqlCmd = $dbh->prepare($sqlStatement);
$sqlCmd->execute();
@EasySetTableNames = @{$dbh->selectcol_arrayref($sqlStatement)};
print "hi";
并通过ODBC
#!/usr/bin/perl -w
use strict;
use DBI;
# Replace datasource_name with the name of your data source.
# Replace database_username and database_password
# with the SQL Server database username and password.
my $data_source = "dbi:MSSQL:test";
my $user = "test";
my $password = "test";
# Connect to the data source and get a handle for that connection.
my $dbh = DBI->connect($data_source, $user, $password)
or die "Can't connect to $data_source: $DBI::errstr";
# This query generates a result set with one record in it.
my $sql = "SELECT 1 AS test_col";
# Prepare the statement.
my $sth = $dbh->prepare($sql)
or die "Can't prepare statement: $DBI::errstr";
# Execute the statement.
$sth->execute();
# Print the column name.
print "$sth->{NAME}->[0]\n";
# Fetch and display the result set value.
while (my @row = $sth->fetchrow_array) {
print "@row\n";
}
# Disconnect the database from the database handle.
$dbh->disconnect;
任何帮助你可以提供将是如此赞赏。
Re“DBI是否直接支持SQL SERVER?”这取决于个人DBD。大多数人不知道ODBC。 DBD :: ODBC是明显的例外。 – ikegami
哼,您使用的DBD :: MSSQL在CPAN上不存在! – ikegami
“Class :: DBI :: MSSQL”的文档表示在引擎盖下使用了'DBD :: ODBC'。 – tjd