I no longer use DBI for my database queries so I can't help you there..
If that's the way you want to go, you might consider using DBI::ODBC
instead (I never had any problems there) and check it's documentation
for syntaxes.

However, this code has always worked for me on a Win32 platform, while
connecting to SQL server..  It uses a native Win32 COM object that is
built into every version of windows at least since Windows NT 4.0.

Results on my SQL server...

spt_monitor - 69575286
spt_values - 85575343
spt_fallback_db - 117575457
spt_fallback_dev - 133575514
spt_fallback_usg - 149575571
dtproperties - 253959981
spt_datatype_info_ext - 529436960
spt_datatype_info - 545437017
spt_server_info - 561437074
spt_provider_types - 1457440266
MSreplication_options - 1931153925

#code

use Win32::OLE;
use Win32::OLE::Const ('Microsoft ActiveX Data Objects 2.6 Library');
 
call_sql("select name,id from sysobjects where xtype = 'U'",$records);
if (Win32::OLE->LastError() != 0) {
  die 0;
}
while (!$records->{EOF}) {
  print $records->Fields("name")->{Value}." -
".$records->Fields("id")->{Value}."\n";
  $records->{MoveNext};
  if ($records->{EOF}) {
    loop;
  }
}
 
sub call_sql {
  my $query = $_[0];
 
  my $user = "username";
  my $pass = "password";#look at the commented $Conn->{Open} line below
if
                        #you want to use passwords instead of trusted
connections (NT Auth)
  my $db = "master";
  my $appname = "whatdoyouwanttocallyourapplication";
  my $server = "servername";
  my $recordset;
    
  my $Conn = Win32::OLE->new("ADODB.Connection");
  if (Win32::OLE->LastError() != 0) {
    print "Failed creating ADODB.Connection object -> ".
Win32::OLE->LastError()."\n";
    return 0;
  }
  $Conn->{ConnectionTimeout} = 15;
  #$Conn->{Open} = "DRIVER={SQL
Server};SERVER=$server;APP=$appname;UID=$user;PWD=$pass;DATABASE=$db;";
  $Conn->{Open} = "DRIVER={SQL
Server};SERVER=$server;APP=$appname;DATABASE=$db;trusted_coinnections=ye
s;";
  if (Win32::OLE->LastError() != 0) {
    print "Failed opening ADODB.Connection object with DB info-> ".
Win32::OLE->LastError()."\n";
    return 0;
  }
  my $Cmd = Win32::OLE->new("ADODB.Command");
  if (Win32::OLE->LastError() != 0) {
    print "Failed creating ADODB.Command object ->
".Win32::OLE->LastError()."\n";
    return 0;
  }
  $Cmd->{CommandText} = $query;
  $Cmd->{CommandType} = adCmdText;
  $Cmd->{ActiveConnection} = $Conn;
  $Cmd->{Prepared} = 1;
  $Cmd->{CommandTimeout} = 45;#seconds to wait for query before
returning an error
  $RS = $Cmd->Execute();
 
  if (Win32::OLE->LastError() != 0) {
    print "Failed opening ADODB.Recordset object for Command ->
(".Win32::OLE->LastError().")\n";
    return 0;
  } else {
    $_[1] = $RS;
    return 1;
  }
}


________________________________

From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Patrix Diradja
Sent: Tuesday, February 06, 2007 2:30 AM
To: perl-win32-users@listserv.ActiveState.com
Subject: Who does "MoveNext" belong to?


Dear my friends....

I am writing a program use activeperl 5.8, MSSQL and on Win32 Env.

Here is my code:
===
#!/usr/bin/perl
use Tk;
use Cwd;
use DBI::ADO;
use WriteExcel;
use strict;
use Win32::OLE qw( in );

my $dsn="sigma";
my $uname="sa";
my $pword="penguin";
my @bd4l=("AprovaApp1");

my $strsqltab4l="select name from sys.tables";
my $dbh2 = DBI->connect("dbi:ADO:$dsn", $uname, $pword)
   || die "Could not open SQL connection.";
my $rsnya = $dbh2->prepare($strsqltab4l);
$rsnya->execute();

while(!$rsnya->{EOF}){
    my $tab4l = $rsnya->fetchrow_array;
    print "\$tab4l: $tab4l \n";
    $rsnya->movenext;
}
====
but than comes problem that I can not solve.

The error message is:
"
Can't get DBI::st=HASH(0x1d2d3f4)->{EOF}: unrecognised attribute name at
C:/Perl/site/lib/DBD/ADO.pm line 1277.
Can't locate object method "movenext" via package "DBI::st" at Untitled1
line 23.
"

Please tell me why.

Thank you very much in advance.



________________________________

Sekarang dengan penyimpanan 1GB
http://id.mail.yahoo.com/
<http://sg.rd.yahoo.com/mail/id/footer/def/*http://id.mail.yahoo.com/> 

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to