List Info

Thread: Re: Balasan: Re: perl can not do query: "use $database"?




Re: Balasan: Re: perl can not do query: "use $database"?
country flaguser name
United States
2007-02-07 15:40:55
I've never used an ADO database.  (I stick with Oracle and
MySQL.)   
So, I'm sorry if I can't help you more.

 From what I see in the DBD::ADO documentation, it looks
like the  
connection strings are a little different from what I've
seen.  I  
included some relevant documentation (hopefully it makes
sense to you  
in an ADO context).

DBD::ADO docs:
http://search.cpan.org/~sgoeldner/DBD-ADO-2
.96/lib/DBD/ADO.pm#connect

---
Quote:

Use the DBI connect method to establish a database
connection:

   my $dbh = DBI->connect("dbi:ADO:$dsn", $usr,
$pwd, $att ) or die  
$DBI::errstr;

where

   $dsn - is an ADO ConnectionString
   ...

An ADO ConnectionString usually contains either a 'Provider'
or a  
'File Name' argument. If you omit these arguments, Provider
defaults  
to MSDASQL (Microsoft OLE DB Provider for ODBC). Therefore
you can  
pass an ODBC connection string (with DSN or DSN-less) as
valid ADO  
connection string. If you use the OLE DB Provider for ODBC,
it may be  
better to omit this additional layer and use DBD::ODBC with
the ODBC  
driver.

In addition the following attributes may be set in the
connection string:

   Attributes
   CommandTimeout
   ConnectionString
   ConnectionTimeout
   CursorLocation
   DefaultDatabase
   IsolationLevel
   Mode

---

Also, a quick internet search led me to the following page
with ADO  
connection strings.  You'll have to convert the VBScript to
Perl, but  
the connection strings/connection parameters should look
similar.

htt
p://www.carlprothman.net/Default.aspx?tabid=81

Once you get connected, it should be easy from here on out
;)

Good Luck,
Charles Alderman


Quoting Patrix Diradja <patrixdiradjayahoo.co.id>:

> Dear my friend, Charles.
>
>   I Use Perl on Windows Vista, MS SQL Server 2005, DBI,
ADO.
>
>   I create 'myperl' as DSN from ODBC Administration
Tools.
>
>   Here is my connection string:
>   my $dbh1 =   
>
DBI->connect("dbi:ADO:database=gua;host=127.0.0.1;po
rt=1433",   
> $uname, $pword)
>   || die "Could not open SQL connection."
>
>
>   But why the connection is failed?
>
>   Here is the error message:
>   DBI
connect('database=gua;host=127.0.0.1;port=1433','sa',...)  

> failed: Can't Open Connection
'database=gua;host=127.0.0.1;port=1433'
>
>   Please tell me why.
>
>
> Charles Alderman <aspncharliealdermania.com> wrote:
>   With DBI you never need to "use" a
particular database. You may be
> used to the "use" command through a
particular command-line or shell
> into the database that you're using. But with the DBI,
you should
> specify the database you want to connect to in the data
source name
> (first) parameter of the connect() method.
>
> http://search.cpan.org/~timb/DBI-1.53/DBI.pm#DBI_C
lass_Methods
>
>> From the DBI docs (under the connect class
method):
>
> Examples of $data_source values are:
>
> dbiriverNam
e:database_name
> dbiriverNam
e:database_namehostname:port
> dbiriverNam
e:database=database_name;host=hostname;port=port
>
>
> It is a little out of date, but I've found the book
Programming the
> Perl DBI by Alligator Descartes and Tim Bunce to be a
very good
> introduction to learning how to use the DBI. I've had
the book since
> it came out, and I still refer back to it when I'm
doing database
> programming.
>
> http://www.amazon.
com/Programming-Perl-DBI-Alligator-Descartes/dp/1565926994/s
r=1-1/qid=1170858081/ref=pd_bbs_sr_1/102-6346332-4332146?ie=
UTF8&s=books
>
> I just noticed on Amazon that it looks like a new
version of the book
> is coming out this May. So, you may want to wait to buy
the book.
>
> http://www.amazon.com/Programmi
ng-Perl-DBI-Tim-Bunce/dp/0596005865/sr=1-2/qid=1170858081/re
f=pd_bbs_2/102-6346332-4332146?ie=UTF8&s=books
>
> Good Luck,
> Charles Alderman
>
>
> Quoting Patrix Diradja
> :
>
> [Hide Quoted Text]
> Dear my friends,
>
> I wonder why my perl can not execute query "use
$database".
>
> Please tell me where is my fault.
>
> Here is the error message and my code:
> ===
> #error message
> DBD::ADO::db do warning: Can't Execute 'use gua'
> ===
> #my code:
> #!/usr/bin/perl
> use strict;
> use DBD::ADO;
> use DBI;
> my $dsn="sigma";
> my $uname="sa";
> my $pword="penguin";
> my $host="127.0.0.1";
> my bd4l=("gua");
>
> print "I am dumping... bd4ln";
> my $elemenbd4l;
> foreach $elemenbd4l(bd4l){
> my $strbd4l="use $elemenbd4l";
> print "$strbd4ln";
> my $dbh1 = DBI->connect("dbi:ADO:$dsn",
$uname, $pword)
> || die "Could not open SQL connection.";
> my $rsnya = $dbh1->do($strbd4l);
>
>
> ---------------------------------
> Sekarang dengan penyimpanan 1GB
> http://id.mail.yahoo.com/
> _______________________________________________
> Perl-Win32-Database mailing list
> Perl-Win32-Databaselistserv.ActiveState.com
> To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs
>
>
>
> ---------------------------------
> Lelah menerima spam? Surat Yahoo! mempunyai
perlindungan terbaik   
> terhadap spam.
>  http://id.mail.yahoo.com/


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

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )