Is PERL --> MS SQL really that difficult?
Is PERL --> MS SQL really that difficult?
am 25.04.2007 23:24:40 von Robert
Is it just me, or is using perl on a linux server to extract
information from an MS SQL server insanely difficult? Has no one
else struggled with this? Here is my set up:
FC4 -> PERL w/DBI -> DBD::ODBC -> unixODBC -> FreeTDS
The irony is that all I need to do is a single simple select from a
single table, and this is something I would run once a day. Yet the
process of getting perl to talk to an MSSQL server seems
disproportionately convoluted.
I am hoping some reader of this list will help me identify where my
attempts are failing. The error that I get when I try to run the
script is this:
Can't connect to data source driver={SQL
Server};Server=<192.168.0.149>;
database=;uid=; pwd=;, no database
driver specified and DBI_DSN env var not set at ./feedback.pl line 11
However, my understanding is that the DBI_DSN env var (which I have
not explicitly set, not am I sure what to set it to if necessary) is
only called if the $data_source in the connect() statement is empty.
My connect() statement is as follows:
$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=
;uid=; pwd=;';
I have seen other syntax for the connect statement for other
databases such as MySQL and Oracle but never for MSSQL. I have
searched dbi.perl.org as well for example syntax but all the examples
I can find there are also for non-MS databases. If anyone knows of
an alternative syntax that they know for certain works for MSSQL that
would be terrific.
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. Further, I specified the install dir for
unixODBC when I installed DBD::ODBC through cpan. Finally, I
registered FreeTDS with unixODBC using template files and odbcinst
commands.
What am I missing here? It seems to me that there is some piece of
the puzzle that I am overlooking that will bring all of this
together. If no one knows the answer I would love to at least see
some pointers to guides/tutorials/examples etc of how this set up is
supposed to work. The examples at dbi.perl.org and in Programming
the Perl DBI seem to never include MSSQL examples, unfortunately.
Robert
Re: Is PERL --> MS SQL really that difficult?
am 26.04.2007 00:09:52 von Robert
"Why can't we all just get along?" --unknown (by me)
I understood from the start that I would be raging against the
machine but I was hoping there would be fellow ragers to help me
along. I am _so_ close. I can feel it. But I really need some help to
get it the rest of the way.
Robert
On Apr 25, 2007, at 5:37 PM, Jonathan Leffler wrote:
>
> On 4/25/07, Robert Denton wrote: Is it just
> me, or is using perl on a linux server to extract
> information from an MS SQL server insanely difficult?
>
> Of course it is - don't you think MS struggles to make sure it is
> as difficult as possible, to ensure you use their system and not
> Linux?
>
> --
> Jonathan Leffler #include
> Guardian of DBD::Informix - v2007.0226 - http://dbi.perl.org
> "Blessed are we who can laugh at ourselves, for we shall never
> cease to be amused."
RE: Is PERL --> MS SQL really that difficult?
am 26.04.2007 00:19:56 von simon.windsor
Hi
It is not difficult!
Use freetds and DBD::Sybase.
At work, I access Oracle, MySQL, Postgres and MS-SQL databases from a
reporting server (Solaris) using perl DBI. It all works as it should!
All the best
Simon
-----Original Message-----
From: Robert Denton [mailto:robert@headsprout.com]
Sent: 25 April 2007 23:10
To: dbi-users@perl.org
Subject: Re: Is PERL --> MS SQL really that difficult?
"Why can't we all just get along?" --unknown (by me)
I understood from the start that I would be raging against the
machine but I was hoping there would be fellow ragers to help me
along. I am _so_ close. I can feel it. But I really need some help to
get it the rest of the way.
Robert
On Apr 25, 2007, at 5:37 PM, Jonathan Leffler wrote:
>
> On 4/25/07, Robert Denton wrote: Is it just
> me, or is using perl on a linux server to extract
> information from an MS SQL server insanely difficult?
>
> Of course it is - don't you think MS struggles to make sure it is
> as difficult as possible, to ensure you use their system and not
> Linux?
>
> --
> Jonathan Leffler #include
> Guardian of DBD::Informix - v2007.0226 - http://dbi.perl.org
> "Blessed are we who can laugh at ourselves, for we shall never
> cease to be amused."
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.463 / Virus Database: 269.6.0/775 - Release Date: 24/04/2007
17:43
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.463 / Virus Database: 269.6.0/775 - Release Date: 24/04/2007
17:43
Re: Is PERL --> MS SQL really that difficult?
am 26.04.2007 08:55:25 von cstrep
Robert Denton wrote:
> Is it just me, or is using perl on a linux server to extract information
> from an MS SQL server insanely difficult? Has no one else struggled
> with this? Here is my set up:
It's just you and probably someone else.
> FC4 -> PERL w/DBI -> DBD::ODBC -> unixODBC -> FreeTDS
I can suggest you a shorter path: DBI + DBD::Sybase + FreeTDS.
Some limitations apply, mainly lack of placeholders support
(but I didn't check recent freetds status). YMMV of course.
Please take a look at the archives. There has been plenty of
discussions in the past about this.
- Small thread about how to setup the thing:
http://www.nntp.perl.org/group/perl.dbi.users/2006/02/msg285 66.html
- FreeTDS FAQ:
http://www.freetds.org/faq.html#Which.Perl.library.should.I. use
- Look at example 6.2:
http://www.freetds.org/userguide/perl.htm
Simple web searches for "perl DBI FreeTDS DBD::Sybase" are also
going to help a lot.
--
Cosimo
Re: Is PERL --> MS SQL really that difficult?
am 26.04.2007 10:32:27 von Tim.Bunce
On Wed, Apr 25, 2007 at 05:24:40PM -0400, Robert Denton wrote:
>
> $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=;uid=; pwd=;';
That needs to have "dbi:ODBC:" at the start.
It's confusing because there term 'data source' (or DSN, Data Source Name)
refers to two different things: the "DBI DSN" and the "Driver DSN".
What you're using is the Driver DSN. Adding the dbi:ODBC: prefix turns
it into a DBI DSN.
Read the connect() section of the DBI docs again and let me know how it
could be improved.
For DBI 1.55 I've changed the message to read:
"Can't connect to data source '$dsn' because I can't work out what driver to use (it doesn't seem to contain a 'dbi:driver:' prefix and DBI_DRIVER env var is not set)"
Tim.
p.s. I've no idea if the value your using for $data_source is valid,
I just know DBI->connect needs the "dbi:ODBC:" at the start.
Re: Is PERL --> MS SQL really that difficult?
am 26.04.2007 10:33:19 von hjp
--jousvV0MzM2p6OtC
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
On 2007-04-25 17:24:40 -0400, Robert Denton wrote:
> Can't connect to data source driver=3D{SQL Server};Server=3D<192.168.0.14=
9>;=20
> database=3D;uid=3D; pwd=3D;, no databas=
e driver=20
> specified and DBI_DSN env var not set at ./feedback.pl line 11
[...]
>=20
> $dbh =3D DBI->connect( $data_source, $username, $password );
>=20
> And my $data_source var is set to this:
>=20
> my $data_source =3D 'driver=3D{SQL Server};Server=3D<192.168.0.149>;=20
> database=3D
> ;uid=3D; pwd=3D;';
[...]
>=20
> As for the other part of the error, "no database driver specified", I am =
not=20
> sure what else I need to do to make perl aware of the FreeTDS driver. I h=
ave=20
> 'use DBI;' in the top of the script which is supposed to be sufficient. =
In=20
> 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?=20
=46rom "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 c=
onâ=90
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=3D{SQL Server};Server=3D<192.168.0.149>;database=3D
edback>;uid=3D;pwd=3D;'.
hp
--=20
_ | 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
--jousvV0MzM2p6OtC
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFGMGPOMdFfQa64PCwRApW2AJ9Wo3u4Eb2qfYLQ3946PezTzlYYRQCc DeZC
AZjovFnkahdbNvsHQieMENY=
=uI6L
-----END PGP SIGNATURE-----
--jousvV0MzM2p6OtC--
Re: Is PERL --> MS SQL really that difficult?
am 26.04.2007 10:50:45 von Martin.Evans
Robert Denton wrote:
> Is it just me, or is using perl on a linux server to extract information
> from an MS SQL server insanely difficult? Has no one else struggled
> with this?
It is not that difficult but you've taken a free route which is slightly
harder than a few commercial ones. You haven't got the money for a
commercial solution but if you had tried OOB or our sql server driver
they would have checked your Perl was OK, checked DBI and DBD::ODBC was
installed (and if not given recommendations), created a unixODBC/OOB
data source which connected to your actual SQL Server, demonstrated data
coming back through isql and through Perl and shown you the DBI
connection string to use.
Anyway, to your problem:
> Here is my set up:
>
> FC4 -> PERL w/DBI -> DBD::ODBC -> unixODBC -> FreeTDS
>
> The irony is that all I need to do is a single simple select from a
> single table, and this is something I would run once a day. Yet the
> process of getting perl to talk to an MSSQL server seems
> disproportionately convoluted.
>
> I am hoping some reader of this list will help me identify where my
> attempts are failing. The error that I get when I try to run the script
> is this:
>
> Can't connect to data source driver={SQL Server};Server=<192.168.0.149>;
> database=;uid=; pwd=;, no database
> driver specified and DBI_DSN env var not set at ./feedback.pl line 11
The error is telling you that you failed to specify a database driver
i.e. you have not prefixed your connection string with "dbi" and then a
driver name "ODBC" e.g.
dbi:ODBC:your_odbc_connection_string_goes_here
(see the connect method in the DBI documentation - perldoc DBI)
Fix this first. Then you've got further issues with your ODBC connection
string as the "driver" attribute should be "DRIVER" (as the ODBC spec
says). If you use "driver=" you'll get a unixODBC error like this:
[unixODBC][Driver Manager]Data source name not found, and no default
driver specified (SQL-IM002)
I'm also assuming you don't really have <> in your connection string -
if you do remove them. So you should end up with:
my $dsn = q/dbi:ODBC:DRIVER={SQL Server};Server=ip_address;attr=value/;
DBI->connect($dsn, $database_username, $database_password);
where "attr=value" represents all your other attributes.
However, you should note that the driver string in {} needs to be the
exact string name for your driver as it is in the odbcinst.ini file or
unixODBC won't know what driver you mean i.e. your odbcinst.ini file
might look like:
[SQL Server]
Driver = /usr/local/lib/libxxx.so
> However, my understanding is that the DBI_DSN env var (which I have not
> explicitly set, not am I sure what to set it to if necessary) is only
> called if the $data_source in the connect() statement is empty. My
> connect() statement is as follows:
>
> $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=
> ;uid=; pwd=;';
see above.
> I have seen other syntax for the connect statement for other databases
> such as MySQL and Oracle but never for MSSQL. I have searched
> dbi.perl.org as well for example syntax but all the examples I can find
> there are also for non-MS databases. If anyone knows of an alternative
> syntax that they know for certain works for MSSQL that would be terrific.
You'll find a potentially useful tutorial ( Perl DBI/DBD::ODBC Tutorial
Part 3 - Connecting Perl on UNIX or Linux to Microsoft SQL Server) at:
http://www.easysoft.com/developer/languages/perl/sql_server_ unix_tutorial.html
It uses our driver for examples but most will apply equally to any ODBC
driver.
You may also find the Linux/UNIX ODBC article below useful:
http://www.easysoft.com/developer/interfaces/odbc/linux.html
> 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. Further, I specified the install dir for unixODBC when I
> installed DBD::ODBC through cpan. Finally, I registered FreeTDS with
> unixODBC using template files and odbcinst commands.
>
> What am I missing here? It seems to me that there is some piece of the
> puzzle that I am overlooking that will bring all of this together. If no
> one knows the answer I would love to at least see some pointers to
> guides/tutorials/examples etc of how this set up is supposed to work.
> The examples at dbi.perl.org and in Programming the Perl DBI seem to
> never include MSSQL examples, unfortunately.
>
> Robert
Good luck.
Martin
--
Martin J. Evans
Easysoft Limited
http://www.easysoft.com
Gofer to PC (was: Is PERL --> MS SQL really that difficult?)
am 26.04.2007 10:51:36 von Tim.Bunce
On Wed, Apr 25, 2007 at 05:24:40PM -0400, Robert Denton wrote:
> Is it just me, or is using perl on a linux server to extract
> information from an MS SQL server insanely difficult? Has no one
> else struggled with this? Here is my set up:
>
> FC4 -> PERL w/DBI -> DBD::ODBC -> unixODBC -> FreeTDS
>
> The irony is that all I need to do is a single simple select from a
> single table, and this is something I would run once a day. Yet the
> process of getting perl to talk to an MSSQL server seems
> disproportionately convoluted.
You could also take a look at DBD::Proxy. That would let you use
DBD::ODBC on a windows PC with a genuine MSSQL ODBC driver.
But you'd need to run a DBI Proxy Server on the PC.
DBD::Gofer would let you do something similar but in a different kind of way.
You'd need perl, DBI, and DBD::ODBC installed on the PC. Then test your
script on the PC to make sure it works and the DSN is correct.
If you can ssh into the PC [1] then using DBD::Gofer may be as simple
as this...
Copy the script over to the unix box. No need to change the DSN at all.
Set the DBI_AUTOPROXY env var to something like this:
DBI_AUTOPROXY='dbi:Gofer:transport=stream;url=ssh:user@pc.yo ur.domain.com'
then just run the script!
The DBI_AUTOPROXY setting will arrange for DBD::Gofer to be used to
proxy the requests via an ssh connection to your PC.
There's no need to have a 'gofer server' running on the PC. The gofer
stream transport starts the gofer server-side code once it has
connected to the PC.
I'm hoping more people will start using gofer and get involved in
helping shape its development.
Tim.
[1] http://www.google.com/search?q=ssh+windows
Re: Gofer to PC (was: Is PERL --> MS SQL really that difficult?)
am 26.04.2007 16:29:44 von Robert
These look like some great options and I will keep them in mind for
future projects, especially DBI::Gofer. In this instance, however,
the server I am working with is "production frozen" so to speak and I
cannot install anything on it at all. All I can do is ask it for
information. I am pursuing the other ideas offered (sybase, connect
() syntax improvements, etc) for now. Thanks for the tips!
Robert
On Apr 26, 2007, at 4:51 AM, Tim Bunce wrote:
> On Wed, Apr 25, 2007 at 05:24:40PM -0400, Robert Denton wrote:
>> Is it just me, or is using perl on a linux server to extract
>> information from an MS SQL server insanely difficult? Has no one
>> else struggled with this? Here is my set up:
>>
>> FC4 -> PERL w/DBI -> DBD::ODBC -> unixODBC -> FreeTDS
>>
>> The irony is that all I need to do is a single simple select from a
>> single table, and this is something I would run once a day. Yet the
>> process of getting perl to talk to an MSSQL server seems
>> disproportionately convoluted.
>
> You could also take a look at DBD::Proxy. That would let you use
> DBD::ODBC on a windows PC with a genuine MSSQL ODBC driver.
> But you'd need to run a DBI Proxy Server on the PC.
>
> DBD::Gofer would let you do something similar but in a different
> kind of way.
>
> You'd need perl, DBI, and DBD::ODBC installed on the PC. Then test
> your
> script on the PC to make sure it works and the DSN is correct.
>
> If you can ssh into the PC [1] then using DBD::Gofer may be as simple
> as this...
>
> Copy the script over to the unix box. No need to change the DSN at
> all.
> Set the DBI_AUTOPROXY env var to something like this:
>
>
> DBI_AUTOPROXY='dbi:Gofer:transport=stream;url=ssh:user@pc.yo ur.domain.
> com'
>
> then just run the script!
>
> The DBI_AUTOPROXY setting will arrange for DBD::Gofer to be used to
> proxy the requests via an ssh connection to your PC.
>
> There's no need to have a 'gofer server' running on the PC. The gofer
> stream transport starts the gofer server-side code once it has
> connected to the PC.
>
> I'm hoping more people will start using gofer and get involved in
> helping shape its development.
>
> Tim.
>
> [1] http://www.google.com/search?q=ssh+windows
RE: Gofer to PC (was: Is PERL --> MS SQL really that difficult?)
am 26.04.2007 17:03:35 von Philip.Garrett
Robert Denton wrote:
> These look like some great options and I will keep them in mind for
> future projects, especially DBI::Gofer. In this instance, however,
> the server I am working with is "production frozen" so to speak and I
> cannot install anything on it at all. All I can do is ask it for
> information. I am pursuing the other ideas offered (sybase, connect
> () syntax improvements, etc) for now. Thanks for the tips!
Remember that you don't have to install anything on the server itself --
just on any Windows PC that can talk ADO or ODBC to the MSSQL server and
run the DBI proxy server.
- Philip
Re: Is PERL --> MS SQL really that difficult?
am 26.04.2007 20:18:28 von Robert
Okay, as it tunrs out maybe it is not all that difficult
afterall... With the help from someone form the FreeTDS developers
team I got it to work. All I had to do was the following:
~~~~~~
> Since I just got this set up for myself...
>
> odbc.ini:
>
> [ODBC Data Sources]
> TEST = Microsoft SQL Server 2000
>
> [TEST]
> Driver = /usr/lib/libtdsodbc.so
> Description = TEST Data
> Trace = No
> Server = 192.168.100.250
> Database = TEST
> ;Port = 4444
> TDS_Version = 8.0
>
> ----------------
>
> /etc/freetds.conf
>
> [SERVER]
> host = 192.168.100.250 # server.test.local
> port = 1433
> tds version = 8.0
>
> -----------------
>
> #!/usr/local/bin/perl
> #
> use DBI;
>
> my $dbh = DBI->connect("dbi:ODBC:TEST", 'DOMAIN\user', 'domainpwd',
> {PrintError => 1, RaiseError => 1, LongTruncOk=>1});
>
> die "Unable for connect to server $DBI::errstr"
> unless $dbh;
~~~~~
My biggest error, other than borrowing unproven connect() syntax from
who-knows-what-google-return, was in not declaring "dbi:ODBC:" in
from of the data source and also in not defining my odbc.ini file.
Many thanks to everyone who contributed to the resolution of this issue
Robert
On Apr 26, 2007, at 4:50 AM, Martin Evans wrote:
> Robert Denton wrote:
>> Is it just me, or is using perl on a linux server to extract
>> information from an MS SQL server insanely difficult? Has no one
>> else struggled with this?
>
> It is not that difficult but you've taken a free route which is
> slightly harder than a few commercial ones. You haven't got the
> money for a commercial solution but if you had tried OOB or our sql
> server driver they would have checked your Perl was OK, checked DBI
> and DBD::ODBC was installed (and if not given recommendations),
> created a unixODBC/OOB data source which connected to your actual
> SQL Server, demonstrated data coming back through isql and through
> Perl and shown you the DBI connection string to use.
>
> Anyway, to your problem:
>
>> Here is my set up:
>> FC4 -> PERL w/DBI -> DBD::ODBC -> unixODBC -> FreeTDS
>> The irony is that all I need to do is a single simple select from
>> a single table, and this is something I would run once a day. Yet
>> the process of getting perl to talk to an MSSQL server seems
>> disproportionately convoluted.
>> I am hoping some reader of this list will help me identify where
>> my attempts are failing. The error that I get when I try to run
>> the script is this:
>> Can't connect to data source driver={SQL
>> Server};Server=<192.168.0.149>;
>> database=;uid=; pwd=;, no
>> database driver specified and DBI_DSN env var not set at ./
>> feedback.pl line 11
>
> The error is telling you that you failed to specify a database
> driver i.e. you have not prefixed your connection string with "dbi"
> and then a driver name "ODBC" e.g.
>
> dbi:ODBC:your_odbc_connection_string_goes_here
>
> (see the connect method in the DBI documentation - perldoc DBI)
>
> Fix this first. Then you've got further issues with your ODBC
> connection string as the "driver" attribute should be "DRIVER" (as
> the ODBC spec says). If you use "driver=" you'll get a unixODBC
> error like this:
>
> [unixODBC][Driver Manager]Data source name not found, and no
> default driver specified (SQL-IM002)
>
> I'm also assuming you don't really have <> in your connection
> string - if you do remove them. So you should end up with:
>
> my $dsn = q/dbi:ODBC:DRIVER={SQL
> Server};Server=ip_address;attr=value/;
> DBI->connect($dsn, $database_username, $database_password);
>
> where "attr=value" represents all your other attributes.
>
> However, you should note that the driver string in {} needs to be the
> exact string name for your driver as it is in the odbcinst.ini file or
> unixODBC won't know what driver you mean i.e. your odbcinst.ini file
> might look like:
>
> [SQL Server]
> Driver = /usr/local/lib/libxxx.so
>
>
>> However, my understanding is that the DBI_DSN env var (which I
>> have not explicitly set, not am I sure what to set it to if
>> necessary) is only called if the $data_source in the connect()
>> statement is empty. My connect() statement is as follows:
>> $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=
>> ;uid=; pwd=;';
>
> see above.
>
>
>> I have seen other syntax for the connect statement for other
>> databases such as MySQL and Oracle but never for MSSQL. I have
>> searched dbi.perl.org as well for example syntax but all the
>> examples I can find there are also for non-MS databases. If
>> anyone knows of an alternative syntax that they know for certain
>> works for MSSQL that would be terrific.
>
> You'll find a potentially useful tutorial ( Perl DBI/DBD::ODBC
> Tutorial Part 3 - Connecting Perl on UNIX or Linux to Microsoft SQL
> Server) at:
>
> http://www.easysoft.com/developer/languages/perl/
> sql_server_unix_tutorial.html
>
> It uses our driver for examples but most will apply equally to any
> ODBC driver.
>
> You may also find the Linux/UNIX ODBC article below useful:
> http://www.easysoft.com/developer/interfaces/odbc/linux.html
>
>> 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. Further, I
>> specified the install dir for unixODBC when I installed DBD::ODBC
>> through cpan. Finally, I registered FreeTDS with unixODBC using
>> template files and odbcinst commands.
>> What am I missing here? It seems to me that there is some piece
>> of the puzzle that I am overlooking that will bring all of this
>> together. If no one knows the answer I would love to at least see
>> some pointers to guides/tutorials/examples etc of how this set up
>> is supposed to work. The examples at dbi.perl.org and in
>> Programming the Perl DBI seem to never include MSSQL examples,
>> unfortunately.
>> Robert
>
> Good luck.
>
> Martin
> --
> Martin J. Evans
> Easysoft Limited
> http://www.easysoft.com
Re: Is PERL --> MS SQL really that difficult?
am 26.04.2007 22:41:31 von Martin.Evans
Robert Denton wrote:
> Okay, as it tunrs out maybe it is not all that difficult
> afterall... With the help from someone form the FreeTDS developers
> team I got it to work. All I had to do was the following:
>
I'm happy you are up and running.
> ~~~~~~
>
>> Since I just got this set up for myself...
>>
>> odbc.ini:
>>
>> [ODBC Data Sources]
>> TEST = Microsoft SQL Server 2000
>>
>> [TEST]
>> Driver = /usr/lib/libtdsodbc.so
>> Description = TEST Data
>> Trace = No
>> Server = 192.168.100.250
>> Database = TEST
>> ;Port = 4444
>> TDS_Version = 8.0
>>
In fairness to anyone else that might read this and copy it, it is not
actually correct if you are using
unixODBC which does not have an "ODBC Data Sources" section at all. Now
I am wondering
if you were really using unixODBC or in fact iODBC or some other driver
manager.
Your principle problem was neglecting to specify dbi:ODBC in the DBI
connection string (which
you concede below) and it was compounded by using driver= instead of
DRIVER= in the ODBC
part of the connection string. Had you corrected these, I'm sure you
would have connected ok
as freeTDS knows about unixODBC and happily works with it.
>> ----------------
>>
>> /etc/freetds.conf
>>
>> [SERVER]
>> host = 192.168.100.250 # server.test.local
>> port = 1433
>> tds version = 8.0
>>
>> -----------------
>>
>> #!/usr/local/bin/perl
>> #
>> use DBI;
>>
>> my $dbh = DBI->connect("dbi:ODBC:TEST", 'DOMAIN\user', 'domainpwd',
>> {PrintError => 1, RaiseError => 1, LongTruncOk=>1});
>>
>> die "Unable for connect to server $DBI::errstr"
>> unless $dbh;
>
>
In actual fact if you read the FAQs mentioned in a previous posting on
this thread you will
see that although the above works, 'dbi:ODBC:DSN=TEST' is better - see
http://www.easysoft.com/support/kb/kb00097.html for why.
> ~~~~~
>
> My biggest error, other than borrowing unproven connect() syntax from
> who-knows-what-google-return, was in not declaring "dbi:ODBC:" in
> from of the data source and also in not defining my odbc.ini file.
> Many thanks to everyone who contributed to the resolution of this issue
>
> Robert
>
>
Interestingly, an age old issue arises out of your post which is what
the ODBC specification says
you should report as an error for certain situations e.g. DSN not found
and no DEFAULT found....
In reality, on UNIX no one writes a default section in their odbc.ini
file so the misdirection to a
DEFAULT driver nearly always confuses. The reality is when you specified
driver={xxx} the
driver manager could not find a DSN= or a DRIVER= so it errored with the
less than helpful error
that ODBC says it should. I will pass this on to Nick (@unixODBC) to see
if he can be persuaded
to deviate from the the spec and provide a slightly more useful message
(as Tim has done to a different
degree in DBI).
Martin