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

Hi Perl experts,

Very new to Perl. I am having issues trying to get DBI to communicate to a SQL server 2008 DB.

I am trying to avoid using ODBC here.

install_driver(MSSQL) failed: Can't locate object method "set_sql" via package "Class::DBI::MSSQL" at C:/Perl/lib/DBD/MSSQL.pm line 79. Compilation failed in require at (eval 19)C:/Perl/site/lib/DBI.pm:744 line 3.

I am new to Perl and I suspect I have screwed up how to install some libraries

use strict; use warnings; use diagnostics; use Class::DBI::Loader; use DBI; #use replace; use File::Glob ':glob'; #Variable Declarations ############# #---Database Credentials my $DBUserName = "******"; my $DBPassword = "****"; my $DBName = "dbi:MSSQL:dbservername"; #------Used in Database Transactions my $dbh = ""; my $sqlStatement = ""; my $sqlCmd = ""; #---Variables used to gather Easy Set Table names my @EasySetTableNames = (); #------Establish DB Connection $dbh = DBI->connect( $DBName, $DBUserName, $DBPassword,{ PrintError => + 0,AutoCommit => 0}) || die "Database connection creation failed: $DBI::errstr\n"; # Get the Easy Set Tables #---These tables in the Insight Database all start with AI_ so get at + list of those tables $sqlStatement = "SELECT * from tableA "; $sqlCmd = $dbh->prepare($sqlStatement); $sqlCmd->execute(); @EasySetTableNames = @{$dbh->selectcol_arrayref($sqlStatement)}; print "hi";

Any help you can provide would be so appreciated.

Thanks,

AJ

  • Comment on DBI for SQL Server issue - can't locate object method "set_sql" via package "Class::DBI::MSSQL
  • Download Code

Replies are listed 'Best First'.
Re: DBI for SQL Server issue - can't locate object method "set_sql" via package "Class::DBI::MSSQL
by taint (Chaplain) on Nov 25, 2013 at 20:53 UTC
    I'm going to take a chance here, and ask;
    Have you installed the MSSQL adapter for DBI: Class::DBI::MSSQL?

    I haven't had the opportunity to work on a winboxen to deal with Perl, and MSSQL. But the error you submitted looks suspiciously like DBI can't find the MSSQL Class.

    --Chris

    #!/usr/bin/perl -Tw
    use Perl::Always or die;
    my $perl_version = (5.12.5);
    print $perl_version;

      Hi Chris,

      I do have it installed, I copied the CPAN tar and extracted it to lib\class\dbi

        Hmm...
        You didn't take the standard "install" approach?
        tar xvz Module-Name-xxx.tar.gz cd Module-Name-xxx perl ./Makefile.PL make make test make install PREFIX=/my/perl_directory
        I'm pertty sure that the Module will not be properly registered, otherwise.
        While you could attempt
        use lib ('/path/to/perl/modules');
        I'm not sure why you wouldn't simply choose a "standard" install for this module.

        Anyway. Just my thoughts on it.

        --Chris

        #!/usr/bin/perl -Tw
        use Perl::Always or die;
        my $perl_version = (5.12.5);
        print $perl_version;
Re: DBI for SQL Server issue - can't locate object method "set_sql" via package "Class::DBI::MSSQL
by marinersk (Priest) on Nov 25, 2013 at 20:27 UTC
    I don't use Class::DBI::Loaderso I could be out in left field here, but I normally just do something like the stuff hidden behind this <readmore>tag. It's for SQLite, so you'll need to adjust the connection string for MS SQL Server, MySQL, PostGreSQL, and Oracle.

      Many thanks but I still get the same error

      install_driver(mssql) failed: Can't locate object method "set_sql" via package "Class::DBI::MSSQL" at C:/Perl/lib/DBD/mssql.pm line 79. Compilation failed in require at (eval 23)C:/Perl/site/lib/DBI.pm:744 line 3.