mistermuv
asked on
Perl Connect to Sql Server 2005
Hi Experts
Windows Server 2003
MS SQL Server 2005
I require a perl script that executes a sql select statement and outputs the result to a text file.
This perl script will be run inside an Openview policy.
The sql isn't anythng fancy, something like:
select count(USER_ID) from USERS where STATUS = 'Open'
How can I do this?
Thanks in advance
Windows Server 2003
MS SQL Server 2005
I require a perl script that executes a sql select statement and outputs the result to a text file.
This perl script will be run inside an Openview policy.
The sql isn't anythng fancy, something like:
select count(USER_ID) from USERS where STATUS = 'Open'
How can I do this?
Thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Is there a way without installing DBD-ODBC package?
The DBI module is a generic interface for perl to talk to any database. Behind it are DBD::* modules, where each one is designed to talk to a specific database. This allows your perl code to be written independent of which database you are using - you just tell it (through the $dsn) which DBD driver to use. Using DBI along with one of the DBD drivers is by far the most common method to having perl talk to a database.
So, is it DBD::ODBC that you don't want to install, or you don't want to install any modules?
If you just want to avoid DBD::ODBC, these DBD modules should work to talk to ms sql server:
DBD::FreeTDS
DBD::ADO
They use the DBI module, so the code above should work as is. This is by far the recommended method.
If you are trying to avoid DBI completly, there are a few modules that might help:
Win32::ODBC
Win32::OLE with ADO
Win32::ADO
These are far less standard methods of connecting perl to a database.
So, is it DBD::ODBC that you don't want to install, or you don't want to install any modules?
If you just want to avoid DBD::ODBC, these DBD modules should work to talk to ms sql server:
DBD::FreeTDS
DBD::ADO
They use the DBI module, so the code above should work as is. This is by far the recommended method.
If you are trying to avoid DBI completly, there are a few modules that might help:
Win32::ODBC
Win32::OLE with ADO
Win32::ADO
These are far less standard methods of connecting perl to a database.
If using ActiveState Perl, do: ppm install DBD::ODBC
DBI should already exist, but DBD::* usually requires install. If you are also missing DBI just install it the same way with ppm.