Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Perl Monk, Perl Meditation
 
PerlMonks  

Connect to MS SQL on Linux

by drodinthe559 (Monk)
on Jan 08, 2010 at 17:56 UTC ( #816374=perlquestion: print w/ replies, xml ) Need Help??
drodinthe559 has asked for the wisdom of the Perl Monks concerning the following question:

Perl Gurus: I trying to connect my perl script to a MS SQL Server from a Suse 11. I've tried using Freetds but was unsuccessful. I then tried downloading the Sybase AES ODBC libraries, but I'm not sure if just simply coping the Sybase.pm into the Perl library will work. Below is my script. Your help will be appreciated.
#!/usr/bin/perl -w use strict; use warnings; #You might need to define parameters for the input. use DBI; use Getopt::Long qw(:config no_ignore_case); my ($status, $failed, $host, $verbose, $timeout); my $VERSION = 0.1; my $HELP = 0; # Default values $failed = 0; my %STATUSCODE = ( 'OK' => '0', 'WARNING' => '1', 'CRITICAL' => '2', 'UNKNOWN' => '3'); my $usage = <<EOF; Test EOF # handle cmdline args my $result = GetOptions( "H|host=s" => \$host, "h|help" => \$HELP,); if( !$result ) { print "ERROR: Problem with cmdline args\n"; print $usage; exit($STATUSCODE{'UNKNOWN'});} if( $HELP ) { print $usage; exit($STATUSCODE{'UNKNOWN'});} if ( !($host) ){ print "ERROR: Missing required arguments\n"; print $usage; exit($STATUSCODE{'UNKNOWN'});}; my $dsn = 'DBI:Sybase:server=prime'; my $dbh = DBI->connect('DBI:Sybase:server=test;UID=sa;PWD=;'); if (!$dbh){die "Could not open connection to DSN because of [$!]";} my $query = $dbh->selectall_arrayref("SELECT COGIPF_STATUS FROM [PVP21_Audit].[dbo].[COGIPF_AGENTRUN] WHERE [COGIPF_LOCALTIMESTAMP] >= CONVERT(VarChar(20), +GetDate() +1,101)", { Slice => {} } ); foreach $query (@$query) { if ($query->{COGIPF_STATUS} eq 'Failed') {$failed = 1} } unless (@$query) { $failed = 1 }; if ( $failed == 0 ) { print "Jobs Succeeded\n"; exit($STATUSCODE{'OK'}); }elsif ( $failed == 1 ){ print "Job Failure\n"; exit($STATUSCODE{'CRITICAL'}); }else{ print "Undetermined error\n"; exit($STATUSCODE{'UNKNOWN'}); }

Comment on Connect to MS SQL on Linux
Download Code
Re: Connect to MS SQL on Linux
by moritz (Cardinal) on Jan 08, 2010 at 18:12 UTC
    I then tried downloading the Sybase AES ODBC libraries, but I'm not sure if just simply coping the Sybase.pm into the Perl library will work. Below is my script. Your help will be appreciated.

    I'm pretty sure you need to install DBD::Sybase if you want to connect with the Sybase backend.

    The README file of that module tells you what's needed to install it.

    Perl 6 - links to (nearly) everything that is Perl 6.
Re: Connect to MS SQL on Linux
by zwon (Monsignor) on Jan 08, 2010 at 21:58 UTC
    I've tried using Freetds but was unsuccessful.

    I've tried freetds and DBD::Sybase on Ubuntu about month ago and was successful. Perhaps you should explain how you've been unsuccessfull with freetds, and what error messages you're getting from your script.

    It's not enough to just copy Sybase.pm, as there also should be Sybase.so. Have you tried to install module using package manager for your distribution?

Re: Connect to MS SQL on Linux
by afoken (Parson) on Jan 09, 2010 at 15:30 UTC

    This is a really frequently asked question.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: Connect to MS SQL on Linux
by mje (Deacon) on Jan 11, 2010 at 09:08 UTC
Re: Connect to MS SQL on Linux
by tokpela (Chaplain) on Jan 11, 2010 at 10:26 UTC

    You should also investigate using the dbiproxy script that comes with DBI

    distribution.

    You first setup a proxy server using the dbiproxy script that is provided with DBI on the Windows box. Then you use DBD::Proxy on the Linux box to connect passing through the proxy.

    There is a chapter on this in the Programming the Perl DBI book by O'Reilly - 8.2. Database Proxying

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://816374]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (13)
As of 2014-04-16 10:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (422 votes), past polls