develooper Front page | perl.dbi.users | Postings from April 2007

Re: Is PERL --> MS SQL really that difficult?

Thread Previous | Thread Next
From:
Peter J. Holzer
Date:
April 26, 2007 01:33
Subject:
Re: Is PERL --> MS SQL really that difficult?
Message ID:
20070426083319.GC19177@wsr.ac.at
On 2007-04-25 17:24:40 -0400, Robert Denton wrote:
> Can't connect to data source driver={SQL Server};Server=<192.168.0.149>; 
> database=<userFeedback>;uid=<testUser>; pwd=<testPass>;, no database driver 
> specified and DBI_DSN env var not set at ./feedback.pl line 11
[...]
> 
> $dbh = DBI->connect( $data_source, $username, $password );
> 
> And my $data_source var is set to this:
> 
> my $data_source = 'driver={SQL Server};Server=<192.168.0.149>; 
> database=<userFeedback>
> ;uid=<testUser>; pwd=<testPass>;';
[...]
> 
> As for the other part of the error, "no database driver specified", I am not 
> sure what else I need to do to make perl aware of the FreeTDS driver. I have 
> 'use DBI;' in the top of the script which is supposed to be sufficient.  In 
> otherword, I do not believe that I need to tell it to use DBD::ODBC.

Why do you believe that? How should DBI know that it is supposed to use
DBD::ODBC (and not DBD::Oracle, DBD::mysql, DBD::Sybase or whatever) if
you don't tell it? 

From "perldoc DBI":

           The $data_source value must begin with ""dbi:"driver_name":"".  The
           driver_name specifies the driver that will be used to make the con‐
           nection. (Letter case is significant.)

So for ODBC, it must start with "dbi:ODBC:". Assuming that the data
source you specified is correct for the ODBC driver, the complete
data source would then be
'dbi:ODBC:driver={SQL Server};Server=<192.168.0.149>;database=<userFeedback>;uid=<testUser>;pwd=<testPass>;'.

	hp

-- 
   _  | Peter J. Holzer    | If I wanted to be "academically correct",
|_|_) | Sysadmin WSR       | I'd be programming in Java.
| |   | hjp@wsr.ac.at      | I don't, and I'm not.
__/   | http://www.hjp.at/ |   -- Jesse Erlbaum on dbi-users

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About