Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

DBI Connect SQL Server SQL-IM002

by mnooning (Sexton)
on May 16, 2008 at 14:19 UTC ( #686924=perlquestion: print w/ replies, xml ) Need Help??
mnooning has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I have tried many versions of the six lines of code pasted further below, and I keep getting the same error messages. I am pasting two such occurrances further below. The end goal is to be on a Linux box - CentOS - and connect to a remote Microsoft SQL Server 2000 on a Windows machine. I am told by the sysadmin that the ODBC drivers are okay on the Windows machine, and noted that people in the Windows world connect with it just fine.

In the code pasted below, the names Server05, Payroll and JohnSmith, the ip address, etcetera are of course substitutions for the real names.

I have also tried setting these three env vars:
$ENV{DBI_DSN} = 'dbi:ODBC:SQL Server'; $ENV{DBI_USER} = 'JohnSmith'; $ENV{DBI_PASS}='Hello';
According to the info below, I have unixODBC and DBD:ODBC installed.
------------ >odbcinst --version unixODBC 2.2.11 ------- >perl -MDBI -e 'DBI-> installed_versions;' Perl : 5.008008 (i386-linux-thread-multi) -> I really ha +ve 5.8.8 OS : linux (2.6.9-42.0.3.elsmp) DBI : 1.604 DBD::Sponge : 12.010002 DBD::Proxy : 0.2004 DBD::ODBC : 1.15 DBD::Gofer : 0.010103 DBD::File : 0.35 DBD::ExampleP : 12.010007 DBD::DBM : 0.03 >odbcinst -j unixODBC 2.2.11 DRIVERS............: /etc/odbcinst.ini SYSTEM DATA SOURCES: /etc/odbc.ini USER DATA SOURCES..: /root/.odbc.ini >odbcinst -q -d [SQL Server] [PostgreSQL]
I cannot figure out what I am doing wrong. Can you spot anything?
----------------------- Paste code example 1 #!/usr/bin/perl -w use strict; use DBI; use DBD::ODBC; my $DSN = 'driver={SQL Server};Server=Server05;database=Payroll;uid=Jo +hnSmith;' my $dbh = DBI->connect("dbi:ODBC:$DSN") or die "$DBI::errstr\n"; ---------------------- End Paste code example 1
---------------------- Paste error message example 1 DBI connect('driver={SQL Server};Server=Fridge;database=Payroll;uid=Jo +hnSmith;','',...) failed: [unixODBC][Driver Manager]Data source name +not found, and no default driver specified (SQL-IM002) at a1.pl line +9 [unixODBC][Driver Manager]Data source name not found, and no default d +river specified (SQL-IM002) ---------------------- End Paste error message example 1
----------------------- Paste code example 2 #!/usr/bin/perl -w use strict; use DBI; use DBD::ODBC; my $DSN = 'driver={SQL Server};Server=10.0.0.53:1433;Database=Payroll; +Uid=JohnSmith;Pwd=Hello;'; my $dbh = DBI->connect("dbi:ODBC:$DSN") or die ($DBI::errstr . "\n"); ---------------------- End Paste code example 2
---------------------- Paste error message example 2 DBI connect('driver={SQL Server};Server=10.0.0.53:1433;Database=Payrol +l;Uid=JohnSmith;Pwd=Hello;','',...) failed: [unixODBC][Driver Manager +]Data source name not found, and no default driver specified (SQL-IM0 +02) at aa.pl line 6 [unixODBC][Driver Manager]Data source name not found, and no default d +river specified (SQL-IM002) ---------------------- Paste error message example 2

Comment on DBI Connect SQL Server SQL-IM002
Select or Download Code
Re: DBI Connect SQL Server SQL-IM002
by pileofrogs (Priest) on May 16, 2008 at 16:42 UTC

    In some linux ODBC implementations you need a config file describing each data source. I think FreeTDS has /etc/freetds.conf, for example. So check the docs for your ODBC stuff.

    --Pileofrogs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://686924]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (15)
As of 2014-12-22 17:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (121 votes), past polls