How do I access a SQL Server database from a Perl script in Linux?

匿名 (未验证) 提交于 2019-12-03 03:00:02

问题:

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?

回答1:

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

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"); 

Good luck!



回答2:

Use the DBD::Sybase module, at one point Sybase and MS SQL Server shared a common codebase.

You may also want to investigate the open source FreeTDS libraries. See the FreeTDS FAQ Question "Which Perl library should I use".



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!