Questions tagged [pyodbc]

pyodbc is a module that allows you to use Python to make a database connection using ODBC

pyodbc is a Python 2.x and 3.x module that allows you to use ODBC to connect to almost any database from Windows, Linux, OS/X, and more.

It implements the Python Database API Specification v2.0, but additional features have been added to further simplify database programming.

pyodbc is licensed using an MIT license, so it is free for commercial and personal use. You can even use the source code in your own projects.

Installing can be done by running:

pip install pyodbc

Most Linux distributions are starting to provide pre-compiled packages, but those versions are often quite outdated.

Full source code is also available from the GitHub repository.

3768 questions
26
votes
3 answers

Can I use multiple cursors on one connection with pyodbc and MS SQL Server?

I'm using pyodbc on python 2.6 to connect to Microsoft SQL Server 2005. I open a connection, create a couple of cursors: c1 = connection.cursor() c2 = connection.cursor() and then run a query on the first cursor. c1.execute("select * from…
Josh
  • 2,039
  • 3
  • 20
  • 25
26
votes
4 answers

to_sql pyodbc count field incorrect or syntax error

I am downloading Json data from an api website and using sqlalchemy, pyodbc and pandas' to_sql function to insert that data into a MSSQL server. I can download up to 10000 rows, however I have to limit the chunksize to 10 otherwise I get the…
Ryan
  • 277
  • 1
  • 4
  • 8
26
votes
7 answers

Authenticate from Linux to Windows SQL Server with pyodbc

I am trying to connect from a linux machine to a windows SQL Server with pyodbc. I do have a couple of constraints: Need to log on with a windows domain account Need to use python3 Need to do it from Linux to Windows Need to connect to a specific…
Esser420
  • 780
  • 1
  • 8
  • 19
26
votes
3 answers

Binding list to params in Pandas read_sql_query with other params

I've been trying to test various methods for making my code to run. To begin with, I have this list: member_list = [111,222,333,444,555,...] I tried to pass it into this query: query = pd.read_sql_query( """ select member id ,yearmonth from…
Scratch'N'Purr
  • 9,959
  • 2
  • 35
  • 51
26
votes
8 answers

PyODBC : can't open the driver even if it exists

I'm new to the linux world and I want to query a Microsoft SQL Server from Python. I used it on Windows and it was perfectly fine but in Linux it's quite painful. After some hours, I finally succeed to install the Microsoft ODBC driver on Linux Mint…
Joseph Yourine
  • 1,301
  • 1
  • 8
  • 18
25
votes
5 answers

basic pyodbc bulk insert

In a python script, I need to run a query on one datasource and insert each row from that query into a table on a different datasource. I'd normally do this with a single insert/select statement with a tsql linked server join but I don't have a…
Zip184
  • 1,792
  • 2
  • 21
  • 34
24
votes
13 answers

ModuleNotFoundError: No module named 'pyodbc' when importing pyodbc into py script

I've written a short python script which tries to import the pyodbc extension package so I can access my SQL table. import pyodbc as pyodbc cnxn = pyodbc.connect('Driver={SQL Server};' 'Server=DESKTOP-UO8KJOP;' …
Jerry12345678
  • 251
  • 1
  • 2
  • 6
24
votes
9 answers

Error 28000: Login failed for user DOMAIN\\user with pyodbc

I am trying to use Python to connect to a SQL database by using Window authentication. I looked at some of the posts here (e.g., here), but the suggested methods didn't seem to work. For example, I used the following code: cnxn =…
Alex
  • 4,030
  • 8
  • 40
  • 62
24
votes
4 answers

Working with an Access database in Python on non-Windows platform (Linux or Mac)

I want to access the data in a Microsoft Access database. I have some .accdb and .mdb files and want to read them in Python. From my research, pyodbc can only be used on Windows platform, but I am working on Mac OS X. I am new to Python. The other…
user2948166
  • 599
  • 1
  • 9
  • 17
23
votes
4 answers

using pyodbc on linux to insert unicode or utf-8 chars in a nvarchar mssql field

I am using Ubuntu 9.04 I have installed the following package versions: unixodbc and unixodbc-dev: 2.2.11-16build3 tdsodbc: 0.82-4 libsybdb5: 0.82-4 freetds-common and freetds-dev: 0.82-4 I have configured /etc/unixodbc.ini like…
nosklo
  • 217,122
  • 57
  • 293
  • 297
23
votes
6 answers

Common ways to connect to odbc from python on windows?

What library should I use to connect to odbc from python on windows? Is there a good alternative for pywin32 when it comes to odbc? I'm looking for something well-documented, robust, actively maintained, etc. pyodbc looks good -- are there any…
user89021
  • 14,784
  • 16
  • 53
  • 65
22
votes
2 answers

pyodbc - How to perform a select statement using a variable for a parameter

I'm trying to iterate through all the rows in a table named Throughput, but for a specific DeviceName (which I have stored in data['DeviceName']. I've tried the following, but it doesn't work: for row in cursor.execute("SELECT * FROM Throughput…
Parth
  • 1,226
  • 7
  • 28
  • 49
22
votes
2 answers

Cant Create tables in access with pyodbc

I am trying to create tables in a MS Access DB with python using pyodbc but when I run my script no tables are created and no errors are given. My code: #!/usr/bin/env python import pyodbc con = pyodbc.connect(r'DRIVER={Microsoft Access Driver…
wDroter
  • 1,209
  • 4
  • 17
  • 25
22
votes
7 answers

pyodbc - very slow bulk insert speed

With this table: CREATE TABLE test_insert ( col1 INT, col2 VARCHAR(10), col3 DATE ) the following code takes 40 seconds to run: import pyodbc from datetime import date conn = pyodbc.connect('DRIVER={SQL Server Native Client 10.0};' …
sayap
  • 6,169
  • 2
  • 36
  • 40
21
votes
3 answers

Install ODBC driver in Alpine Linux Docker Container

I currently have the following Dockerfile to create my Docker image. FROM python:3.6.6-alpine3.8 # Add dependencies for Python packages pandas, numpy and pyodbc RUN apk add --no-cache curl gcc g++ unixodbc-dev RUN ln -s /usr/include/locale.h…
Alexis.Rolland
  • 5,724
  • 6
  • 50
  • 77