Problem getting Perl - SQL Server connect working - syntax error?
Problem getting Perl - SQL Server connect working - syntax error?
am 15.08.2006 14:59:42 von Chris.Powers
------_=_NextPart_001_01C6C06A.ACF53F24
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Hello,
=20
I'm trying to figure out what syntax issue I have with my Perl code. I
am new at this, so it's probably something basic - simple syntax, but I
don't see it and have looked thru some examples I've found online and
still no luck.
=20
It's a Windows Server, SQL Server db, if it makes a difference, I'm
running the code on one server and the db is on another.
=20
I've got DBD-ODBC and DBI loaded thru PPM, running ActiveState Perl
5.8.8 build 817.
=20
use strict;
use warnings;
use DBI;
use DBD::ODBC;
use Getopt::Std;
use Data::Dumper;
=20
my $db_host =3D "10.15.158.124";
my $db_name =3D "dbname";
my $db_user =3D "id";
my $db_pass =3D "idpassword";
=20
my $dbh =3D
DBI->connect("DBI:ODBC:dbname=3D$db_name:host=3D$db_host;por t=3D3306",
$db_user, $db_pass, { RaiseError =3D> 1 });
=20
>perl record_last_used_rule_db.pl
DBI connect('dbname=3Ddbname:host=3D10.15.158.124;port=3D3306',' id',...)
failed: [Microsoft][ODBC Driver Manager]
Data source name not found and no default driver specified
(SQL-IM002)(DBD: db_login/SQLConnect err=3D-1) at
record_last_used_rule_db.pl line 34
=20
This came originally from something for mysql, I think all I've changed
was updated it to have ODBC, but perhaps there's some other option SQL
Server / ODBC needs? =20
Thanks for the help!
-Chris=20
=20
=20
=20
LEGAL DISCLAIMER=20
The information transmitted is intended solely for the individual or =
entity to which it is addressed and may contain confidential and/or =
privileged material. Any review, retransmission, dissemination or other =
use of or taking action in reliance upon this information by persons or =
entities other than the intended recipient is prohibited. If you have =
received this email in error please contact the sender and delete the =
material from any computer.=20
=20
Seeing Beyond Money is a service mark of SunTrust Banks, Inc.=20
[ST:XCL]=20
=20
=20
=20
=20
------_=_NextPart_001_01C6C06A.ACF53F24--
Re: Problem getting Perl - SQL Server connect working - syntax error?
am 15.08.2006 15:46:42 von jseger
From perldoc DBI:
Examples of $data_source values are:
dbi:DriverName:database_name
dbi:DriverName:database_name@hostname:port
dbi:DriverName:database=database_name;host=hostname;port=por t
You have a colon where you need a semicolon:
DBI->connect("DBI:ODBC:dbname=$db_name:host=$db_host;port=33 06",
On 8/15/06, Powers.Chris wrote:
> Hello,
>
> I'm trying to figure out what syntax issue I have with my Perl code. I
> am new at this, so it's probably something basic - simple syntax, but I
> don't see it and have looked thru some examples I've found online and
> still no luck.
>
> It's a Windows Server, SQL Server db, if it makes a difference, I'm
> running the code on one server and the db is on another.
>
> I've got DBD-ODBC and DBI loaded thru PPM, running ActiveState Perl
> 5.8.8 build 817.
>
> use strict;
> use warnings;
> use DBI;
> use DBD::ODBC;
> use Getopt::Std;
> use Data::Dumper;
>
> my $db_host = "10.15.158.124";
> my $db_name = "dbname";
> my $db_user = "id";
> my $db_pass = "idpassword";
>
> my $dbh =
> DBI->connect("DBI:ODBC:dbname=$db_name:host=$db_host;port=33 06",
> $db_user, $db_pass, { RaiseError => 1 });
>
> >perl record_last_used_rule_db.pl
> DBI connect('dbname=dbname:host=10.15.158.124;port=3306','id',.. .)
> failed: [Microsoft][ODBC Driver Manager]
> Data source name not found and no default driver specified
> (SQL-IM002)(DBD: db_login/SQLConnect err=-1) at
> record_last_used_rule_db.pl line 34
>
> This came originally from something for mysql, I think all I've changed
> was updated it to have ODBC, but perhaps there's some other option SQL
> Server / ODBC needs?
>
> Thanks for the help!
>
> -Chris
>
>
>
> LEGAL DISCLAIMER
> The information transmitted is intended solely for the individual or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of or taking action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you have received this email in error please contact the sender and delete the material from any computer.
>
> Seeing Beyond Money is a service mark of SunTrust Banks, Inc.
> [ST:XCL]
>
>
>
>
>
>
--
------------------------------------------------------------ --------------------------------------------------
The darkest places in hell are reserved for those who maintain their
neutrality in times of moral crisis.
Dante Alighieri (1265 - 1321)
They who would give up an essential liberty for temporary security,
deserve neither liberty or security.
Benjamin Franklin
Our lives begin to end the day we become silent about things that matter.
Martin Luther King
The right of the people to be secure in their persons, houses, papers,
and effects, against unreasonable searches and seizures, shall not be
violated, and no warrants shall issue, but upon probable cause,
supported by oath or affirmation, and particularly describing the
place to be searched, and the persons or things to be seized.
Amendment IV to the Constitution of the United States
------------------------------------------------------------ --------------------------------------------------
RE: Problem getting Perl - SQL Server connect working - syntax er
am 15.08.2006 19:11:26 von campbelb
I've successfully connected to a local MS SQL server (MSDE actually) from ActiveState Perl using the following connect string. This is the DSN-less form described in the docs.
my $dbh = DBI->connect('DBI:ODBC:Driver={SQL Server};server={(local)};database={my_db};','','');
Since your server is on a different machine, presumably you would substitute a host name for "(local)", and supply user and password, but I don't believe I've done that myself.
The docs also describe a DSN form as follows. Of course you have to have the DSN defined on your machine (see the control panel, admin tools).
DBI->connect('dbi:ODBC:mydsn', 'user', 'password');
-----Original Message-----
From: Powers.Chris [mailto:Chris.Powers@SunTrust.com]
Sent: Tuesday, August 15, 2006 6:00 AM
To: dbi-users@perl.org
Subject: Problem getting Perl - SQL Server connect working - syntax
error?
Hello,
I'm trying to figure out what syntax issue I have with my Perl code. I
am new at this, so it's probably something basic - simple syntax, but I
don't see it and have looked thru some examples I've found online and
still no luck.
It's a Windows Server, SQL Server db, if it makes a difference, I'm
running the code on one server and the db is on another.
I've got DBD-ODBC and DBI loaded thru PPM, running ActiveState Perl
5.8.8 build 817.
use strict;
use warnings;
use DBI;
use DBD::ODBC;
use Getopt::Std;
use Data::Dumper;
my $db_host = "10.15.158.124";
my $db_name = "dbname";
my $db_user = "id";
my $db_pass = "idpassword";
my $dbh =
DBI->connect("DBI:ODBC:dbname=$db_name:host=$db_host;port=33 06",
$db_user, $db_pass, { RaiseError => 1 });
>perl record_last_used_rule_db.pl
DBI connect('dbname=dbname:host=10.15.158.124;port=3306','id',.. .)
failed: [Microsoft][ODBC Driver Manager]
Data source name not found and no default driver specified
(SQL-IM002)(DBD: db_login/SQLConnect err=-1) at
record_last_used_rule_db.pl line 34
This came originally from something for mysql, I think all I've changed
was updated it to have ODBC, but perhaps there's some other option SQL
Server / ODBC needs?
Thanks for the help!
-Chris
LEGAL DISCLAIMER
The information transmitted is intended solely for the individual or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of or taking action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you have received this email in error please contact the sender and delete the material from any computer.
Seeing Beyond Money is a service mark of SunTrust Banks, Inc.
[ST:XCL]