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.
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?
Related
When attempting to connect to a PostgreSQL database with ODBC I get the following error:
('08P01', '[08P01] [unixODBC]ERROR: Unsupported startup parameter: geqo (210) (SQLDriverConnect)')
I get this with two different ODBC front-ends (pyodbc for Python and ODBC.jl for Julia), so it's clearly coming from the ODBC library itself. Is there a way to stop it from passing this "geqo" parameter?
An example in pyodbc would be very useful.
Thanks.
The error indicates that the ODBC driver tries to set the geqo parameter in the startup packet, but the PostgreSQL server does not recognize it.
This is bunny because this parameter is exists in all PostgreSQL versions I know, at least down to 7.1.
Is it possible that you are using a fork of PostgreSQL that does not have this parameter?
Another funny thing is that this commit from 2014 removes the geqo setting, so in recent versions of the ODBC driver it should not even be used (unless you specify it explicitly with the Connect Settings setting).
Maybe your problem will vanish if you use a recent ODBC driver version.
Config SSL Mode: allow in ODBC Driver postgres, driver version: 9.3.400
I'm sure this is a stupidly simple issue but I just can't sort it out. I'm trying to open a local database with pyodbc but it won't let me.
The database and script are on the same path, there are no passwords. I only have one installation of Python on my system - Anaconda 3, and this is where pyodbc installed itself when I used PIP to install the Python 3.5, 64 bit whl file from Christoph Gohlke
import pyodbc
pyodbc.connect('Driver={SQL Server};Server=(local);Database=tblGrid.mdb;Trusted_Connection=yes;')
I get the following error:
pyodbc.Error: ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][Shared Memory]SQL Server does not exist or access denied. (17) (SQLDriverConnect)')
Thanks
You need to use the Microsoft Access ODBC driver to open an *.mdb file.
Here is an example of connecting:
pyodbc.connect(
r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\some\path\tblGrid.mdb')
I tried to connect to a remote MSSQL server by using pymssql package but then I get "ImportError: No module named pymssql".
Yes, I have done a pip install pymssql which worked. I also looked into installing Cython but it seems such install would give more headaches, so not worth to attempt with such. If I am not totally wrong, pymssql recuires Cython.
The OS I am using is Windows 10 Professional.
Remote connection to MSSQL does work, since at the other side of the office they are connected to the MSSQL server by software Qlik. The MSSQL server firewall does not block port 1433.
So, since pymssql seems not to work out of the box, I have tried to import pyodbc, which in this case gives some error message and does not connect. To this point I tried different solutions listed here on SE and none worked so far.
Following appears so far to be the most successful approach:
import pyodbc
con = pyodbc.connect('DRIVER={SQL Server};SERVER=gxn.database.windows.net;DATABASE=instantcopy;UID=testdb#gxn;PASSWORD=verysecret')
cur = con.cursor()
con.close()
The error is:
pyodbc.Error: ('28000', "[28000] [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'testdb'.
(18456) (SQLDriverConnect); [01S00] [Microsoft][ODBC SQL Server Driver]Invalid connection string attribute (0); [28000]
[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'testdb'. (18456); [01S00] [Microsoft][OD
BC SQL Server Driver]Invalid connection string attribute (0)")
Any ideas?
Update1:
Using following correction.. I got this line from Azure suggesting following connection string:
Driver={SQL Server Native Client 11.0};Server=tcp:xxx.database.windows.net,1433;Database=xxx-instantorcopy;Uid=xxxtestdb#xxx;Pwd={your_password_here};Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;
Solved:
The password was incorrect. So, if anyone is to attempt to connect to mssql I can tell you that I failed with 3 connectors and finally made it with pyodbc.
Hi everyone this is my first question on this website.
So i'm working on a Python Project at work. And i have to connect my Python/Django application to an HyperfileSQL (Windev) database to write some information on the HyperFile tables.
I've installed pyodbc library to do the job. But when i was trying to make a connection in windows Cmd, it shows me this error:
pyodbc.connect('DRIVER={HyperFileSQL};SERVER=Mondev1;DATABASE=SP_MONTREAL;UI
D=admin;PWD=')
Traceback (most recent call last):
File "", line 1, in
pyodbc.Error: ('01000', "[01000] [Microsoft][ODBC Driver Manager] The
driver doesn't support the version of ODBC behavior that the application reques
ted (see SQLSetEnvAttr). (0) (SQLDriverConnect); [01S00] Invalid connection string attribute (0)")
I really don't understand why the connection failed. Anyone has any idea.
Note: Sorry about my poor english level i'm french :).
If you want to access hyperfile through odbc you need the driver odbc for hyperfilesql.
You need to buy it. Then install it and configure an odbc connection to your database. Here is the documentation :
http://doc.pcsoft.fr/fr-FR/?3044179
Then you will be able to access with python to your database through the odbc driver for hyperfilesql.
Hope it will help.
I am attempting to connect to SQL Server running on Windows XP system from a *nix system on a local server via pymssql. However, the connection fails as shown below
db = pymssql.connect(host='192.168.1.102',user='www',password='test',database='TestDB')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pymssql.pyx", line 457, in pymssql.connect (pymssql.c:6041)
raise InterfaceError(e[0])
pymssql.InterfaceError: Connection to the database failed for an unknown reason.
Things I've tried:
Set SQL Server and browser to run as a network server.
Setup a user 'www'. I also tested this user locally in SQL Studio.
Turned off Windows firewall (temporarily of course).
I am missing SOMETHING - I just don't know what it is. I tried all of the infinite menu options on Windows to no avail. One thing I noticed is that if the Windows Firewall is on (I setup an exception for SQL Server) python pauses a long time and then gives the error. If the firewall is off the error is instant.
Are there any logs I can look at in SQL Server?
Got it! I think the source of the problem was not giving Free TDS the attention it needs. Free TDS is apparently the driver behind pymssql and provides for connectivity to other databases - SQL Server being one of them.
The freetds.conf file is located in /usr/local/etc on my system (Mac Book Pro).
This file contains the defaults from the install. However, I had previously added a definition so that I could connect but forgot about it and unfortunately did not take notes on it.
Anyway, here is an example of what I appended to freetds.conf:
[SomeDB]
host = 192.168.1.102
port = 1219
tds version = 7.0
However, what is puzzling is that I set the port to 1219. I had it set manually to 1433 in SQL Studio. Also, I am using TDS version 0.82 so I don't know how 7.0 fits in.
Next, I tested connectivity using 'tsql' as follows:
tsql -S SomeDB -U www
I enter the password and get a command-line which allows for SQL queries.
Next, I tested connecting using pymssql as follows:
db = pymssql.connect(host='SomeDB',user='www',password='cylon',database='TestDB')
As you can see, I needed to use the host name from the freetds.conf file and NOT the IP directly. I then tested a simple query with additional python code to insure I could read from the database.
I hope this helps someone else in the future.
It looks like you've got this solved, but for anybody else from google that lands here: check to make sure mixed-mode authorization is turned on on your MS SQL Server. It defaults to only allowing Windows authorization, and that will cause this error in pymssql.
is it a windows machine u working on? specify the port 1433.
it seems to be a bug in the mssql client api, which tries to use Namedpipes instead of TCP/IP.