in reply to DBI for SQL Server issue - can't locate object method "set_sql" via package "Class::DBI::MSSQL

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.

#!/usr/bin/perl use strict; use warnings; use DBI; use Data::Dumper; ###################################################################### +########## # SQLite v3+ ###################################################################### +########## my $db_parameters = { AutoCommit => 0, PrintError => 1, }; my $db_name = 'test.db'; my @sql_statements = ( 'create table TST (RECNUM integer primary key, USRNAM character(30 +) );', 'insert into TST values (1, \'burnsg\');', 'insert into TST values (2, \'adamss\');', 'select * from TST order by USRNAM;', ); # Connect my $db_connection_string = "dbi:SQLite:dbname=$db_name"; my $db_handle = DBI->connect($db_connection_string,"","",$db_parameter +s); if ($db_handle->err()) { print "ERROR: $DBI::errstr"; } # Submit SQL statements foreach my $sql_statement (@sql_statements) { my $sql_handle; if ($sql_statement =~ /^\s*SELECT\s+/i) { # SELECT statement: $sql_handle = $db_handle->prepare($sql_statement); if ($db_handle->err()) { print "ERROR: $DBI::errstr"; } else { my $qryres = $sql_handle->execute; if ($db_handle->err()) { print "ERROR: $DBI::errstr"; } else { my @dbrref = @{ $sql_handle->fetchall_arrayref({}) }; print Dumper \@dbrref; } } } else { # Non-SELECT statement $sql_handle = $db_handle->do("$sql_statement"); if ($db_handle->err()) { print "ERROR: $DBI::errstr"; } } } # Commit and disconnect { $db_handle->commit(); if ($db_handle->err()) { print "ERROR: $DBI::errstr"; } $db_handle->disconnect(); if ($db_handle->err()) { print "ERROR: $DBI::errstr"; } } exit;
  • Comment on Re: DBI for SQL Server issue - can't locate object method "set_sql" via package "Class::DBI::MSSQL
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: DBI for SQL Server issue - can't locate object method "set_sql" via package "Class::DBI::MSSQL
by newbieperlperson (Acolyte) on Nov 25, 2013 at 20:59 UTC
    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.