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
|