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
15
votes
1 answer

pyodbc.connect() works, but not sqlalchemy.create_engine().connect()

I am attempting to write a Python script that can take Excel sheets and import them into my SQL Server Express (with Windows Authentication) database as tables. To do this, I am using pandas to read the Excel files into a pandas DataFrame, I then…
KOB
  • 4,084
  • 9
  • 44
  • 88
15
votes
3 answers

Execute SQL file with multiple statements separated by ";" using pyodbc

I am currently writing a script to run multiple SQL files using Python, a little background before you mention alternative methods; this is to automate the scripts and Python is the only tools I have on our windows 2008 server. I have a script that…
Ninjaboy12
  • 181
  • 1
  • 3
  • 7
15
votes
2 answers

PYODBC to Pandas - DataFrame not working - Shape of passed values is (x,y), indices imply (w,z)

I used pyodbc with python before but now I have installed it on a new machine ( win 8 64 bit, Python 2.7 64 bit, PythonXY with Spyder). Before I used to (at the bottom you can find more real examples): columns = [column[0] for column in…
user1350191
  • 311
  • 1
  • 3
  • 9
15
votes
3 answers

Python multiprocessing and database access with pyodbc "is not safe"?

The Problem: I am getting the following traceback and don't understand what it means or how to fix it: Traceback (most recent call last): File "", line 1, in File "C:\Python26\lib\multiprocessing\forking.py", line 342, in main …
tgray
  • 8,826
  • 5
  • 36
  • 41
14
votes
3 answers

Connect to Azure SQL in Python with MFA Active Directory Interactive Authentication without using Microsoft.IdentityModel.Clients.ActiveDirectory dll

To connect to Azure SQL Database using MFA (which is in SSMS as "Active Directory - Universal") Microsoft recommends and currently only has a tutorial on connecting with C# using Microsoft.IdentityModel.Clients.ActiveDirectory Setting…
dmi_
  • 1,187
  • 2
  • 12
  • 26
14
votes
4 answers

Is it possible for 64-bit pyodbc to talk to 32-bit MS access database?

I am using 64-bit python anaconda v4.4 which runs python v3. I have MS Access 2016 32-bit version. I would like to use pyodbc to get python to talk to Access. Is it possible to use 64-bit pyodbc to talk to a MS Access 2016 32-bit database? I…
user3848207
  • 3,737
  • 17
  • 59
  • 104
14
votes
2 answers

Access second result set of stored procedure with SQL or other work-around? Python\pyodbc

I'm using python\pyodbc and would like to access the second result set of a stored procedure. As near as I can tell, pyodbc does not support multiple result sets. Additionally, I can't modify the stored procedure. Are there any options to access the…
G - M
14
votes
3 answers

Iterating over PyoDBC result without fetchall()

I'm trying to process a very large query with pyodbc and I need to iterate over the rows without loading them all at once with fetchall(). Is there a good and principled way to do this?
dave
  • 12,406
  • 10
  • 42
  • 59
13
votes
6 answers

How to properly install pyodbc and drivers on M1 mac

I have a new M1 pro macbook and I'm trying to install pyodbc and relevant drivers on my machine. So far I have installed unixodbc via homebrew and ODBC drivers according to the instructions found here:…
kdot
  • 131
  • 1
  • 1
  • 4
13
votes
0 answers

Connect to sql server from linux environment using putty private key, sqlalchemy and pyodbc

Hi I am trying to read a dataframe from sql server from a linux(ubuntu server). The file(gscm.ppk) has the admin keys in it I have used the following format to connect to sql server: *import urllib import pandas as pd params =…
nsk
  • 141
  • 1
  • 5
13
votes
4 answers

Why would I get a memory error with fast_executemany on a tiny df?

I was looking for ways to speed up pushing a dataframe to sql server and stumbled upon an approach here. This approach blew me away in terms of speed. Using normal to_sql took almost 2 hours and this script was done in 12.54 seconds to push a 100k…
CandleWax
  • 2,159
  • 2
  • 28
  • 46
13
votes
3 answers

pyodbc rowcount only returns -1

How does rowcount work. I am using pyodbc and it's always returning -1. return_query = conn.query_db_param(query, q_params) print(return_query.rowcount) def query_db_param(self, query, params): self.cursor.execute(query,params) …
user3525290
  • 1,557
  • 2
  • 20
  • 47
13
votes
2 answers

pyodbc - error while running application within a container

I am having a python application that uses mssql - instead of using pymssql, i was trying pyodbc. There seems to be no problems while running the application in a Windows local machine. While deploying the application in a dev env packaged as a…
Lakshmi Narayanan
  • 151
  • 1
  • 1
  • 8
13
votes
2 answers

single database connection throughout the python application (following singleton pattern)

My Question is what is the best way to maintain the single database connection in the entire application? Using Singleton Pattern? How? Conditions that are needed to be taken care of: In case of multiple requests, I should be using the same…
Moinuddin Quadri
  • 46,825
  • 13
  • 96
  • 126
13
votes
2 answers

Is it possible to have SQL Server convert collation to UTF-8 / UTF-16

In a project I am working on my data is stored in SQL Server, with the collation Danish_Norwegian_CI_AS. The data is output'ed through FreeTDS and ODBC, to python that handles the data as UTF-8. Some of the characters, like å, ø and æ, are not being…
Rookie
  • 1,590
  • 5
  • 20
  • 34