Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

PERL and MS-SQL Server 2000

by Anonymous Monk
on Apr 17, 2006 at 08:50 UTC ( [id://543777]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

All,
Trying to access MS-SQL Server 2000, from Perl and we are facing couple of issues. But we are able to work with MS-Access. Please let us know on what should be done.
1. We downloaded the DBD-Sybase-1.07 winzip file
2. We extracted all the files from the zipped file to C:\Perl\site\lib\DBD folder, so that dbd-sybase.pm file is made available directly in the DBD folder
3. We included the following code in our program, but we are encountering errors
use DBI; use DBD::ODBC; use DBD::Sybase; BEGIN { $ENV{SYBASE} = 'C:\Program Files\Microsoft SQL Server\80\Tools\BINN'; } my $dbh = DBI->connect('dbi:Sybase:', 'sa', '');
The following is the error message we get. Please let us know what is that we are missing in the installation process. D:\Production>perl ex.pl
Can't locate loadable object for module DBD::Sybase in @INC (@INC contains: C:/Perl/lib C:/Perl/site/lib .) at ex.pl line 5
Compilation failed in require at ex.pl line 5.
BEGIN failed--compilation aborted at ex.pl line 5.

Thanks and Regards

Replies are listed 'Best First'.
Re: PERL and MS-SQL Server 2000
by McDarren (Abbot) on Apr 17, 2006 at 09:38 UTC
    If you are connecting to a MS-SQL server from another win32 box, then you don'y really need to bother with the DBD::Sybase module.

    This is the code that I have (using DBD::ODBC) which works just fine:

    sub connectdb { my ($data_source, $database, $user_id, $passwd ) = qw( server_hostname_or_IP database_instance username password +); my $conn_string = "driver={SQL Server};Server=$data_source;Databas +e=$database;UID=$user_id;PWD=$passwd"; my $dbh = DBI->connect( "DBI:ODBC:$conn_string" ) or die $DBI::err +str; return $dbh; }

    Cheers,
    Darren :)

    PS. It's when you try connecting to a MS-SQL server from a Linux box that the fun really begins! But in that case, I found this tutorial to be an absolute godsend :)

Re: PERL and MS-SQL Server 2000
by VSarkiss (Monsignor) on Apr 17, 2006 at 14:55 UTC

    To access SQL Server from Perl on windows, you have two clear choices and some unclear ones. Using DBD::Sybase is one of the unclear ones.

    Your two simple choices are DBD::ODBC and DBD::ADO. Both of those work very well with SQL Server if you're on a Windows variant. Generally people fall back on using the Sybase driver (with freetds) when they have to connect to SQL Server from a Linux, Unix, or other non-Windows machine.

    A couple of notes in general: Installing some Perl modules requires a compiler; DBD::Sybase is one of them. A very good workaround to having a compiler, if you're using ActiveState Perl, is to use ppm, the Perl Package Manager that comes with the ActiveState installation. You may have to dig around for a particular PPM package; Google is your friend here.

    Even for packages that don't require compilation, it's often better to use an installer like ppm or the CPAN.pm module. That way you'll be sure everything is where it needs to be, that prerequisites are available, and so on.

    Second general note: you don't need to explicitly call out the DBD package you want (in general). You can just do:

    use DBI;
    and the DBI.pm module will take care of the rest.

    HTH

Re: PERL and MS-SQL Server 2000
by strat (Canon) on Apr 17, 2006 at 09:23 UTC

    Try 'dbi:' in uppercase:

    my $dbh = DBI->connect('DBI:Sybase:', 'sa', '');

    Best regards,
    perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

        oops, that's true...

        Then DBD::Sybase doesn't seem to be installed correctly. If there's a Sybase*.ppd in the zip file, try to execute the following command in the directory with the ppd-file (let's assume its name is Sybase-1.2.3.ppd)

        ppm install Sybase-1.2.3.ppd

        http://theoryx5.uwinnipeg.ca/ppms/ might also be interesting for you

        Best regards,
        perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

Re: PERL and MS-SQL Server 2000
by vkon (Curate) on Apr 17, 2006 at 09:42 UTC
    Although I do not have an experience with DBD::Sybase; module, the compilation error strictly shows an error in the use DBD::Sybase; line.

    You probably need install this module "better"; unpacking could be not enough. Which directory you unpacked into?
    Also, it could perfectly be your perl DLLs do not have executable permissions, or so.
    (your file system is NTFS?)

    Make stripped following excerpt from your code to pass compiling:

    use DBI; use DBD::ODBC; use DBD::Sybase;
    and I advice you to get rid of your following hack:
    $ENV{SYBASE} = 'C:\Program Files\Microsoft SQL Server\80\Tools\BINN';

      and I advice you to get rid of your following hack: $ENV{SYBASE} = 'C:\Program Files\Microsoft SQL Server\80\Tools\BINN';

      If you're using DBD::Sybase, you need this line either in a BEGIN block or set in your environment before invoking the script.

      The sybase client libs use the environment variable SYBASE to locate the interfaces (or sql.ini for w32) file. The interfaces file is where the logical name of the database (used in the connection method) is mapped to the actual machine/port.

      -derby
        all true, but such hard-coding of paths isn't good.

        You will have problems running this script elsewhere.

        Much better to find another way of supplying that ENV variable: helper .BAT, or real environment change, or finding installation path via registry, or whatever.

Re: PERL and MS-SQL Server 2000
by jfroebe (Parson) on Apr 17, 2006 at 19:12 UTC

    If accessing MS SQL Server 2000/2005 from Linux/Unix, then use FreeTDS to build the DBD::Sybase against. The reason for this, is that if the SQL Server is using integrated authentication, then Sybase's OpenClient is unable to connect. FreeTDS is able to work with integrated authentication.

    Jason L. Froebe

    Team Sybase member

    No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

      Thanks to each one of you.. Will verify and get back.. Regards

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-03-29 09:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found