Good Morning

Thanks for the e-mails

Will try today

Respectfully

Erich
----- Original Message -----
From: "Chris Snyder" <[EMAIL PROTECTED]>
To: "'Erich Singer'" <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Friday, January 30, 2004 6:41 PM
Subject: RE: ADO connection to SQL Server


> I tested it with a SQL database and it worked.  I did have to make a minor
> change other than the "defined $RS->{EOF}" that I mentioned before.
>
> The statement "if (!$RS)" and "if (!$Conn)" are completely invalid, and
will
> ALWAYS return false (a negated true actually, as "if ($RS)" will always
> return true).
>
> You can change it to:
> if (!$RS->State)
>   and
> if ($Conn->State)
>
> respectively.  That will assist in caputuring an inactive connection or
> recordset.
>
> Also, if you step through this in the debugger, running a Data::Dumper on
> $RS and $Conn will give you a little insight into their respective
> attributes.  So, as I said before, I am willing to bet that it is the DSN
> that is giving you problems
>
> Here is a sample of the DSN I used.  Change the User ID, Password and Data
> Source accordingly.
>
> my $dsn = 'Provider=SQLOLEDB.1;Password=xxx;Persist Security
Info=True;User
> ID=xxx;Initial Catalog=Northwind;Data Source=ServerName';
>
> -- Chris Snyder
>
>
> I Wrote:
>
> >Erich Singer wrote:
> >
> >-- snip --
> >>Hello
> >>
> >>Thanks for the suggestion. I have modified the code to:
> >>
> >>...
> >>$RS->{ActiveConnection} = $Conn;
> >>$RS->{Source} = "SELECT * FROM Orders";
> >>$RS->Open;
> >>#$RS = $Conn->Execute("SELECT * FROM Orders");
> >>if(!$RS) {
> >> $Errors = $Conn->Errors();
> >> print "Errors: \n";
> >> foreach $error (keys %$Errors) {
> >>  print $error->{Description}, "\n";
> >> }
> >> die"Could not execute SQL";
> >>}
> >>while ( !$RS->EOF ) {
> >>...
> >>
> >>Now I get the message:
> >>"Can't call method "value" on an undefined value at line 24"
> >>
> >>Thanks in advance for any suggestion
> >
> >-- snip --
> >
> >Using ADO with perl will sometimes drive you crazy.  It would seem to
> anyone $RS->EOF would return a true if there were no records return.
After
> all, isn't this how it works with VB?  But no, it doesn't.  And you are
> fortunate to not have to learn this after hours of pulling hair.
> >
> >The EOF in $RS->EOF basically returns what is in the Win32::OLE blessed
> hash.  If a select statement does not succeed, because the table wasn't
> there, etc., a number of values in that hash get assigned undef, including
> the EOF and BOF.  So, if you say "while (!$RS->EOF)" on a recordset that
did
> not succeed in opening, then the $RS->EOF returns undef, which negated is
1,
> thus allowing entry into the loop.
> >
> >You can bypass this by changing:
> >while ( !$RS->EOF ) {
> >    to
> >while (defined $RS->{EOF} && !$RS->EOF) {
> >
> >That will enable to to keep from extracting information from records that
> do not exist.  However, that does not tell you the state of your
recordset.
> You can do that by checking the state with $RS->State.  You can also use
> constants, just like the VB constants, with the line:
> >
> >use Win32::OLE::Const 'Microsoft ActiveX Data Objects';
> >
> >Then you can write a line like:
> >
> >if ($RS->State = adStateOpen) {
> >
> >(note that I just take the short cut, and do not actually do that, so the
> syntax might vary)
> >That will make sure the recordset is open, and allow you to distinguish
> from retrieving no records from the select statement and having a problem
> somewhere.
> >
> >Okay, so much for a (not-so-) brief overview of ADO with perl.
> >
> >If you connected to the database and got no records returned, but it was
> not captured with the $RS->EOF statement, that means that something died.
> In all honesty, 98% of the time it is the DSN.  I would double check the
DSN
> (and triple-check).  If you can, validate the username and password,
> database and SQL statement via an external program, like Query Analyzer.
> Validate that you have permissions, etc.
> >
> >If that doesn't work, let me know.  I have a "Northwind" SQL server
> somewhere around here, and can let you know.
> >
> >-- Chris
> >
> >
> >
>

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to