pyodbc problem

Discussion in 'Python' started by Martin Gregorie, Jul 27, 2010.

  1. I have a small problem: I can't get pyodbc to connect to a PostgreSQL
    database. All it does is spit out a malformed error message. When I run
    this:

    ==============================================
    import pyodbc

    dsn = pyodbc.dataSources()
    print "Data sources: %s" % dsn

    conn = pyodbc.connect(dsn="marchive")
    print "ODBC connection: %s" % conn
    ==============================================

    I get this:

    ==============================================
    [kiwi@zappa python]$ python dsncheck.py
    Data sources: {'ma': 'PostgreSQL', 'marchive': 'PostgreSQL'}
    Traceback (most recent call last):
    File "dsncheck.py", line 6, in <module>
    conn = pyodbc.connect(dsn="marchive")
    pyodbc.Error: ('0', '[0] [unixODBC]c (0) (SQLDriverConnectW)')
    ==============================================

    so the data source exists and is evidently found by connect(), whiuch
    seems unable to make sense of it.

    The pgsql module works well, but I would prefer to use ODBC because its
    not so closely bound to a single RDBMS. unixODBC, which I understand
    underlies pyodbc, works OK too:

    ==============================================
    [kiwi@zappa python]$ isql marchive marchive n/a
    +---------------------------------------+
    | Connected! |
    | |
    | sql-statement |
    | help [tablename] |
    | quit |
    | |
    +---------------------------------------+
    SQL> select count(*) from address;
    +---------------------+
    | count |
    +---------------------+
    | 32 |
    +---------------------+
    SQLRowCount returns 1
    1 rows fetched
    SQL> quit
    ==============================================

    Questions:
    - Why does pyodbc blow up when its apparently trying to talk to unixODBC?
    - What does this mean:
    pyodbc.Error: ('0', '[0] [unixODBC]c (0) (SQLDriverConnectW)')

    I'm new to Python, though not to Linux, PostgreSQL, ODBC, C or Java.
    My rig and software:

    Linux: Fedora 12 Where I'm running Python and ODBC,
    Lenovo Thinkpad R61i: Core Duo.
    Fedora 10 Where PostgreSQL is installed,
    IBM NetVista: Pentium III.
    PostgreSQL: 8.3.8
    Python: 2.6.2
    pyodbc 2.1.5-3.fc12 ) By yum from RH repository
    unixODBC 2.2.14-11.fc12 )


    --
    martin@ | Martin Gregorie
    gregorie. | Essex, UK
    org |
     
    Martin Gregorie, Jul 27, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe Salmeri

    pyodbc data corruption problem

    Joe Salmeri, May 19, 2007, in forum: Python
    Replies:
    3
    Views:
    396
    Joe Salmeri
    May 24, 2007
  2. Rajendran
    Replies:
    3
    Views:
    782
    Doug Phillips
    Jun 17, 2007
  3. john.goodleaf

    Problem with pyodbc, Python?

    john.goodleaf, Aug 1, 2008, in forum: Python
    Replies:
    0
    Views:
    326
    john.goodleaf
    Aug 1, 2008
  4. Frank Millman

    pyodbc - problem passing None as parameter

    Frank Millman, Oct 22, 2009, in forum: Python
    Replies:
    0
    Views:
    300
    Frank Millman
    Oct 22, 2009
  5. Tim Golden
    Replies:
    0
    Views:
    692
    Tim Golden
    Oct 22, 2009
Loading...

Share This Page