ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> activeperl
activeperl
Re: ADO connection to SQL Server
by Chris Snyder other posts by this author
Jan 30 2004 9:40PM messages near this date
RE: ADO connection to SQL Server | Re: ADO connection to SQL Server
Erich Singer wrote:

 --- snip ---
> Hello
> 
> I am trying to retrieve data from my local SQL server with the following
code:
> 
> use Win32::OLE;
> $RS   = Win32::OLE-> new("ADODB.Recordset");
> $Conn = Win32::OLE-> new("ADODB.Connection");
> my $dsn =
> 'PROVIDER=Provider=SQLOLEDB.1;Password=cps;Persist Security Info=True;User
ID=cps;Initial
> Catalog=corp_process;Data Source=GVW2KDEVSQL1';
> $Conn-> open($dsn);
> if (!$Conn)
> {
>     die "Could not open connection to DSN because of [$!]";
> }
 --- snip ---

Rather than use the execute statement from the connection, set the
ActiveConnection in the record set to the connection and the open the record
set.

 --- snip ---
> $RS =3D $Conn-> Execute("SELECT * FROM Orders");
> if(!$RS) {
 --- snip ---

instead of that code, try:

$RS-> {ActiveConnection} = $Conn;
$RS-> {Source} = "SELECT * FROM Orders";
$RS-> Open;

if(!$RS) {

I use this code and it works fine.  Also, make sure your DSN is bulletproof.

-- Chris Snyder

_______________________________________________
ActivePerl mailing list
ActivePerl@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Chris Snyder
Erich Singer

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved