4

I have a PostgreSQL running on localhost. I have psqlODBC Driver installed. Now when I try to connect to the server using pyodbc as:

import pyodbc
connection = pyodbc.connect("DRIVER={psqlOBDC};SERVER=localhost;DATABASE=weather;UID=postgres;PWD=password")

but I get this error:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pyodbc.Error: ('08001', '[08001] Already connected. (202) (SQLDriverConnect)')

Whats the problem?

Thanks.

ashokadhikari
  • 1,182
  • 3
  • 15
  • 29
  • Why don't you use a native driver? – fog Jun 01 '12 at 07:11
  • I again came across the same problem. When I installed the postgressql on ubuntu, it worked well, but when i install it on my mac and use the above code, i get the same error. I am using ODBC, so an OBDC driver is required isnt it? What should be done. – ashokadhikari Jun 18 '12 at 16:55

1 Answers1

3

Of course you must install ODBC driver. I don't know Mac, but in Windows there is ODBC Manager where you configure Data Sources. For PostgreSQL driver there is also "Test" button to check if connection can be established.

As fog noticed you can also use other technology to connect to PostgreSQL. If you can use Jython then you can use JDBC driver. There are also native drivers like psycopg, PyGreSQL and pg8000 (pure Python). Can you give them try?

Michał Niklas
  • 53,067
  • 18
  • 70
  • 114