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;port=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 <aspncharlie aldermania.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_Class_Methods
From the DBI docs (under the connect class method):
Examples of $data_source values are:
dbi riverName:database_name dbi riverName:database_name hostname:port dbi riverName: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/sr=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/Programming-Perl-DBI-Tim-Bunce/dp/0596005865/sr=1-2/qid=1170858081/ref=pd_bbs_2/102-6346332-4332146?ie=UTF8&s=books
Good Luck, Charles Alderman
Quoting Patrix Diradja YAHOO.CO.ID>:
[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-Database listserv.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/
|