tsql连接到ODBC,但Perl DBI收到错误

时间:2015-07-09 16:16:27

标签: sql-server perl odbc dbi freetds

  • 客户端是Ubuntu 14.04.1 LTS与MS SQL Server 2005通信.Ubuntu没有注册域。它与MS SQL Server一样位于本地网络内部。
  • Perl 5.18.2使用DBI 1.63和DBD :: ODBC 1.52。
  • 已安装FreeTDS 0.92(使用TDS v4.2)和unixODBC 2.2.14。
  • 命令行中的
  • isql DSN USERNAME PASSWD也不起作用。也许我应该从那开始。我仍然得到同样的错误Unable to connect to data source (SQL-08001).

我的相关配置文件:

2015-07-09 11:55:14 AM
NOTE: TDS version from tsql -C must go into freetds.conf and odbc.ini files

=========================================
/etc/odbcinst.ini:
[FreeTDS]
Description = FreeTDS 0.91 for Microsoft SQL Server 2005
#Driver = /usr/lib/odbc/libtdsodbc.so
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
UsageCount = 1
#Threading = 2
fileusage = 1
dontdlclose = 1

=========================================
/etc/odbc.ini:
[ODBC Data Sources]
ResponseBDO = Response database desc in /etc/odbc/ini

[FreeTDS]
Description = FreeTDS 0.91 driver
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so

[responsebdo]
Driver = FreeTDS
Description = Response MSSQL 2005 ODBC driver
SERVER = sqlsvr.mydomain.com
PORT = 1433
USER = 'domain\domainuser'
Password = mypasswd
Database = r4w_004
# TDS_VERSION should be same as reported by 'tsql -C'.
TDS_Version = 4.2

[Default]
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Description = Default FreeTDS ODBC driver
SERVER = 10.20.30.40
USER = "domain\domainuser"
Database = r4w_4

=========================================
Relevant part of /etc/freetds/freetds.conf:
#   $Id: freetds.conf,v 1.12 2007/12/25 06:02:36 jklowden Exp $
#
# This file is installed by FreeTDS if no file by the same 
# name is found in the installation directory.  
#
# For information about the layout of this file and its settings, 
# see the freetds.conf manpage "man freetds.conf".  
# 
[responsetds]
    #host = 10.20.30.40
    host = sqlsvr.mydomain.com
    port = 1433
    tds version = 4.2
    connect timeout = 20
    timeout = 20
    dump file = /tmp/freetds-resp.log
    instance = MSSQLSERVER  
    use ntlmv2 = yes


=========================================
tsql -C:
Compile-time settings (established with the "configure" script)
                            Version: freetds v0.91
             freetds.conf directory: /etc/freetds
     MS db-lib source compatibility: no
        Sybase binary compatibility: yes
                      Thread safety: yes
                      iconv library: yes
                        TDS version: 4.2
                              iODBC: no
                           unixodbc: yes
              SSPI "trusted" logins: no
                           Kerberos: yes

=========================================
odbcinst --version:
unixODBC 2.2.14

<小时/> Perl连接信息:

$respdsn="dbi:ODBC:Driver={SQL Native Client};Server=10.20.30.40;".
"UID=$respdbuser;PWD=$respdbpw;Database=r4w_004";
$respdbh=DBI->connect($respdsn);

我可以在命令行使用tsql连接到数据库。 但是使用Perl我得到了这个错误:

DBI connect('Driver={SQL Native Client};Server=10.19.1.3;UID=gilson\mwreports;PWD=MR4gilson;Database=r4w_004','',...) failed:
[unixODBC][Driver Manager]Data source name not found, and no default 
driver specified (SQL-IM002) at /home/chuck/perl/gilson/jimv/fedex/fedex.pl line 1557.
 at /usr/lib/perl5/DBI.pm line 691.
        DBI::__ANON__[/usr/lib/perl5/DBI.pm:744](undef, undef) called at /usr/lib/perl5/DBI.pm line 747

<小时/> 我的问题:

  • 是&#34; {SQL Native Client}&#34;在Perl连接字符串中是否正确?它是指odbc.ini或freetds.conf文件中的条目吗?
  • 我在这里失踪了什么?

谢谢。

2 个答案:

答案 0 :(得分:0)

如果你正在使用FreeTDS,那么你的驱动程序就是FreeTDS而不是#34; Sql Native Client&#34;。

尝试使用此行来获取数据库句柄:

my $dbh = DBI->connect("dbi:ODBC:Driver=FreeTDS;Server=10.20.30.40;database=r4w_004", $respdbuser, $respdbpw);

答案 1 :(得分:0)

当我使用tsql可以正常工作但将dbi与perl一起使用时,我遇到了同样的问题。我花了很多时间试图找出问题所在,所以我看到了Adaptive Server的局限性:

  • 名称不能超过30个字符
  • 第一个字符必须是字母(ASCII从a到z,从A到Z)。
  • 其后的字符必须是字母,数字或下划线(_)。

...所以我尝试将32个字符长的密码更改为30个字符,并且可以使用。

tsql接受长密码,但是perl dbi sybase仅接受30个字符。

用于在端口1433上连接到默认实例的命令:

perl -e 'use DBI;DBI->connect("dbi:Sybase:server=10.0.0.1","sa","max_30_characters_longpassword");'

用于连接到命名实例的命令(使用端口udp 1434查找端口):

perl -e 'use DBI;DBI->connect("dbi:Sybase:server=10.0.0.1\\SQL2014","sa","max_30_characters_longpassword");'

当您知道sqlserver正在侦听的端口时,用于连接到命名实例的命令:

perl -e 'use DBI;DBI->connect("dbi:Sybase:server=10.0.0.1:60036","sa","max_30characters_long_password");'

我使用tcpdump监视与sqlserver的连接:

tcpdump -qn dst host 10.0.0.1 &

也许它可以帮助某人。谢谢