buildout-based install with freetds and unixodbc

96 views
Skip to first unread message

fulv

unread,
Jul 2, 2010, 12:25:22 AM7/2/10
to pyodbc
I have freetds and unixodbc, and they both work fine, as I verified
with tsql and isql. But I have a problem with pyodbc:

>>> import pyodbc
>>> conn = pyodbc.connect("DRIVER={TDS};Server=......;Database=......;UID=.....;PWD=....")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source
name not found, and no default driver specified (0)
(SQLDriverConnectW)')


The bigger picture is that I am trying to install this in a Zope
buildout, and I have pysql in the eggs list for the instance, but I
have freetds and unixodbc built by the following buildout parts:

[freetds]
recipe = zc.recipe.cmmi
url = ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
extra_options = --with-tdsver=8.0

[unixodbc]
recipe = zc.recipe.cmmi
url = http://www.unixodbc.org/unixODBC-2.3.0.tar.gz


Could it be that pyodbc does not see the buildout-made unixodbc? And
if so, how do I change buildout to make pyodbc build correctly?

Or what else could be the problem?

Thanks!

Alec Shaner

unread,
Jul 2, 2010, 10:48:58 AM7/2/10
to pyo...@googlegroups.com
I don't think it's an issue of pyodbc not seeing unixODBC, rather a configuration problem. If I try to connect like your example I get the same error. If you can't figure it out, you can try it like this:

>>> import pyodbc
>>> conn = pyodbc.connect("DSN=database;UID=username;PWD=password")

where the "database" matches an entry from your odbc.ini file.

Define a server instance in freetds.conf (host, port, tds version)
Define a driver in odbcinst.ini
Define a database instance in odbc.ini - where the Driver matches one from odbcinst.ini and the Servername matches one from freetds.conf

If you want to see examples of each config let me know.


--
You received this message because you are subscribed to the Google Groups "pyodbc" group.
To post to this group, send email to pyo...@googlegroups.com.
To unsubscribe from this group, send email to pyodbc+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pyodbc?hl=en.


fulv

unread,
Jul 2, 2010, 2:51:54 PM7/2/10
to pyodbc
I get the same error with

>>> conn = pyodbc.connect("DSN=database;UID=username;PWD=password")

I have tried what you said, defining a server instance in
freetds.conf, a driver in odbcinst.ini and a db instance in odbc.ini.
The thing is, when I run the command line tools tsql (from freetds/
bin) and isql (from unixodbc/bin), it all works great.

Is there any way to see which path pyodbc is searching for DSNs or
other configuration files?

Thanks!

On Jul 2, 7:48 am, Alec Shaner <asha...@chumpland.org> wrote:
> I don't think it's an issue of pyodbc not seeing unixODBC, rather a
> configuration problem. If I try to connect like your example I get the same
> error. If you can't figure it out, you can try it like this:
>
> >>> import pyodbc
> >>> conn = pyodbc.connect("DSN=database;UID=username;PWD=password")
>
> where the "database" matches an entry from your odbc.ini file.
>
> Define a server instance in freetds.conf (host, port, tds version)
> Define a driver in odbcinst.ini
> Define a database instance in odbc.ini - where the Driver matches one from
> odbcinst.ini and the Servername matches one from freetds.conf
>
> If you want to see examples of each config let me know.On Fri, Jul 2, 2010 at 12:25 AM, fulv <fulviocas...@gmail.com> wrote:
> > I have freetds and unixodbc, and they both work fine, as I verified
> > with tsql and isql.  But I have a problem with pyodbc:
>
> > >>> import pyodbc
> > >>> conn =
> > pyodbc.connect("DRIVER={TDS};Server=......;Database=......;UID=.....;PWD=....")
> > Traceback (most recent call last):
> >  File "<stdin>", line 1, in ?
> > pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source
> > name not found, and no default driver specified (0)
> > (SQLDriverConnectW)')
>
> > The bigger picture is that I am trying to install this in a Zope
> > buildout, and I have pysql in the eggs list for the instance, but I
> > have freetds and unixodbc built by the following buildout parts:
>
> > [freetds]
> > recipe = zc.recipe.cmmi
> > url =
> >ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
> > extra_options = --with-tdsver=8.0
>
> > [unixodbc]
> > recipe = zc.recipe.cmmi
> > url =http://www.unixodbc.org/unixODBC-2.3.0.tar.gz
>
> > Could it be that pyodbc does not see the buildout-made unixodbc?  And
> > if so, how do I change buildout to make pyodbc build correctly?
>
> > Or what else could be the problem?
>
> > Thanks!
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "pyodbc" group.
> > To post to this group, send email to pyo...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > pyodbc+un...@googlegroups.com<pyodbc%2Bunsu...@googlegroups.com>
> > .

fulv

unread,
Jul 2, 2010, 4:29:45 PM7/2/10
to pyodbc
I made some progress: the buildout-installed unixodbc got installed
in /var/zope/..../buildout/parts/unixodbc, and the .ini files were in
an etc folder under that, as expected. I copied them to /etc, and
then it all started working again.
For a pyodbc egg that's downloaded and installed by buildout (and in a
python virtual environment, at that) I would expect it to know *not*
to use the system-wide /etc files. I would love to be able to
configure pyodbc in buildout to tell it explicitly where to grab the
ini files from.

Thanks, Alec! First I tried your advice, too, but it didn't work.
The thing is, both freetds and unixodbc were already working fine,
since I did have valid freetds.conf, odbcinst.ini and odbc.ini files,
as evidenced by running the command-line tools tsql and isql,
respectively. It really was pyodbc that couldn't find the driver
manager.

Thanks all!

On Jul 2, 7:48 am, Alec Shaner <asha...@chumpland.org> wrote:
> I don't think it's an issue of pyodbc not seeing unixODBC, rather a
> configuration problem. If I try to connect like your example I get the same
> error. If you can't figure it out, you can try it like this:
>
> >>> import pyodbc
> >>> conn = pyodbc.connect("DSN=database;UID=username;PWD=password")
>
> where the "database" matches an entry from your odbc.ini file.
>
> Define a server instance in freetds.conf (host, port, tds version)
> Define a driver in odbcinst.ini
> Define a database instance in odbc.ini - where the Driver matches one from
> odbcinst.ini and the Servername matches one from freetds.conf
>
> If you want to see examples of each config let me know.
>
> On Fri, Jul 2, 2010 at 12:25 AM, fulv <fulviocas...@gmail.com> wrote:
> > I have freetds and unixodbc, and they both work fine, as I verified
> > with tsql and isql.  But I have a problem with pyodbc:
>
> > >>> import pyodbc
> > >>> conn =
> > pyodbc.connect("DRIVER={TDS};Server=......;Database=......;UID=.....;PWD=....")
> > Traceback (most recent call last):
> >  File "<stdin>", line 1, in ?
> > pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source
> > name not found, and no default driver specified (0)
> > (SQLDriverConnectW)')
>
> > The bigger picture is that I am trying to install this in a Zope
> > buildout, and I have pysql in the eggs list for the instance, but I
> > have freetds and unixodbc built by the following buildout parts:
>
> > [freetds]
> > recipe = zc.recipe.cmmi
> > url =
> >ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
> > extra_options = --with-tdsver=8.0
>
> > [unixodbc]
> > recipe = zc.recipe.cmmi
> > url =http://www.unixodbc.org/unixODBC-2.3.0.tar.gz
>
> > Could it be that pyodbc does not see the buildout-made unixodbc?  And
> > if so, how do I change buildout to make pyodbc build correctly?
>
> > Or what else could be the problem?
>
> > Thanks!
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "pyodbc" group.
> > To post to this group, send email to pyo...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > pyodbc+un...@googlegroups.com<pyodbc%2Bunsu...@googlegroups.com>
> > .

Alec Shaner

unread,
Jul 5, 2010, 11:01:51 AM7/5/10
to pyo...@googlegroups.com
I can't say for sure, but I assumed pyodbc just referenced the ODBC library (libodbc.so) and it's up to unixODBC to know about config files.

You can run odbcinst -j to see what unixODBC is looking for.

Mine is like this:

unixODBC 2.3.0
DRIVERS............: /etc/unixODBC/odbcinst.ini
SYSTEM DATA SOURCES: /etc/unixODBC/odbc.ini
FILE DATA SOURCES..: /etc/unixODBC/ODBCDataSources
USER DATA SOURCES..: /home/alec/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8

I've always used the system wide config files, but I think unixODBC will prefer the user's .odbc.ini file over those.

To unsubscribe from this group, send email to pyodbc+un...@googlegroups.com.

fulv

unread,
Jul 8, 2010, 5:19:06 PM7/8/10
to pyodbc
That's good to know, thanks! Mine is like this (when I run it from /
var/zope/edufund/buildout/parts/unixodbc/bin):

unixODBC 2.3.0
DRIVERS............: /var/zope/edufund/buildout/parts/unixodbc/etc/
odbcinst.ini
SYSTEM DATA SOURCES: /var/zope/edufund/buildout/parts/unixodbc/etc/
odbc.ini
FILE DATA SOURCES..: /var/zope/edufund/buildout/parts/unixodbc/etc/
ODBCDataSources
USER DATA SOURCES..: /home/zope/.odbc.ini
SQLULEN Size.......: 4
SQLLEN Size........: 4
SQLSETPOSIROW Size.: 2



The user DSN file /home/zope/.odbc.ini is empty.

So this is weird. I confirmed that if I remove the ini files from /
etc, pyodbc.connect does not work, and if I remove the ones in /var/
zope/edufund/buildout/parts/unixodbc/etc, it does.

I figured that maybe there is a system-wide unixodbc installed, and I
looked for it. I found a /usr/bin/odbcinst and a bunch of libodbc*.so
files in /usr/lib/, as well as a /usr/lib/odbc/ directory.

As expected, when running /usr/bin/odbcinst -j, I get:

unixODBC 2.2.11
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
USER DATA SOURCES..: /home/zope/.odbc.ini

I tar-ed and removed all the system-wide unixodbc stuff, as well as
the /etc/odbc*.ini files. Now pyodbc.connect no longer works. tsql
and isql still work. It all starts working again after I restore the /
etc/odbc*.ini files.

Bottom line, pyodbc only works if the odbc*.ini files are in /etc, no
matter what odbcinst -j says.



On Jul 5, 8:01 am, Alec Shaner <asha...@chumpland.org> wrote:
> I can't say for sure, but I assumed pyodbc just referenced the ODBC library
> (libodbc.so) and it's up to unixODBC to know about config files.
>
> You can run odbcinst -j to see what unixODBC is looking for.
>
> Mine is like this:
>
> unixODBC 2.3.0
> DRIVERS............: /etc/unixODBC/odbcinst.ini
> SYSTEM DATA SOURCES: /etc/unixODBC/odbc.ini
> FILE DATA SOURCES..: /etc/unixODBC/ODBCDataSources
> USER DATA SOURCES..: /home/alec/.odbc.ini
> SQLULEN Size.......: 8
> SQLLEN Size........: 8
> SQLSETPOSIROW Size.: 8
>
> I've always used the system wide config files, but I think unixODBC will
> prefer the user's .odbc.ini file over those.
>
> > <pyodbc%2Bunsu...@googlegroups.com<pyodbc%252Buns...@googlegroups.com>

fulv

unread,
Jul 8, 2010, 7:59:14 PM7/8/10
to pyodbc
Never mind! After my last message, I realized that I had not actually
*deleted* the libodbc*.so libraries from /usr/lib.
When I did delete those libraries, I could no longer even import
pyodbc, because it complained about opening libodbc.so.1.

So the mystery is now much less mysterious. pyodbc is indeed loading
the system-wide unixodbc libraries, and doesn't find the ones
installed locally by buildout. And you are probably right about
pyodbc not knowing anything about the ini files.

The last piece of the mystery would be to find out how to have
buildout configure the local pyodbc to find the local unixodbc,
instead of the system-wide one.


On Jul 5, 8:01 am, Alec Shaner <asha...@chumpland.org> wrote:
> I can't say for sure, but I assumed pyodbc just referenced the ODBC library
> (libodbc.so) and it's up to unixODBC to know about config files.
>
> You can run odbcinst -j to see what unixODBC is looking for.
>
> Mine is like this:
>
> unixODBC 2.3.0
> DRIVERS............: /etc/unixODBC/odbcinst.ini
> SYSTEM DATA SOURCES: /etc/unixODBC/odbc.ini
> FILE DATA SOURCES..: /etc/unixODBC/ODBCDataSources
> USER DATA SOURCES..: /home/alec/.odbc.ini
> SQLULEN Size.......: 8
> SQLLEN Size........: 8
> SQLSETPOSIROW Size.: 8
>
> I've always used the system wide config files, but I think unixODBC will
> prefer the user's .odbc.ini file over those.
>
> > <pyodbc%2Bunsu...@googlegroups.com<pyodbc%252Buns...@googlegroups.com>

Alec Shaner

unread,
Jul 8, 2010, 9:12:24 PM7/8/10
to pyo...@googlegroups.com
You could try modifying your shared library search path. If you only need unixodbc for this particular application you can try to edit /etc/ld.so.conf and put /var/zope/edufund/buildout/parts/lib (or wherever your unixodbc buildout puts the shared libraries) ahead of everything else. There may be a better way but it's been so long since I was a C programmer and had to worry about linking stuff. Maybe your virtualenv lets you customize the search path?

To unsubscribe from this group, send email to pyodbc+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages