如何在Linux中从Perl脚本访问SQL Server数据库? [英] How do I access a SQL Server database from a Perl script in Linux?

查看:130
本文介绍了如何在Linux中从Perl脚本访问SQL Server数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Linux(Ubuntu 8.10)计算机上有一个Perl脚本,我需要将数据写入SQL Server数据库.我一直在尝试使用DBD :: ODBC模块,但无法连接它.在哪里可以获得免费/开源驱动程序以用于ODBC连接,或者在Linux上的Perl中还有另一种方法可以做到这一点?

I have a Perl script on a Linux (Ubuntu 8.10) machine and I need to write data to a SQL Server Database. I've been trying to use the DBD::ODBC module but I can't get it to connect. Where can I get a free/open source driver to use to use for the ODBC connection or is there another way to do this from Perl on Linux?

推荐答案

我使用 unixODBC堆栈连接到SQL Server 2005 freeTDS (这是驱动程序)和DBD :: ODBC.

I connect to SQL Server 2005 with the stack of unixODBC, freeTDS (this is the driver) and DBD::ODBC.

安装这些组件后,编辑/etc/unixODBC/odbc.ini如下:

After you install these components, edit /etc/unixODBC/odbc.ini to read like this:

[DNS]
Description = my database
Driver = /usr/lib/libtdsodbc.so #path to freeTDS driver
Server = ServerName
Database = DatabaseName
Port = 1433 #sql server default port
TDS_Version = 9.0 #9.0 is sql server 2005
try domain login = yes
try server login = yes
nt domain = DOMAIN

如果一切顺利,您应该可以进行以下连接:

If all goes well, you should be able to connect with:

$dbh = DBI->connect('dbi:ODBC:DNS', "userName", "passWord");

祝你好运!

这篇关于如何在Linux中从Perl脚本访问SQL Server数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆