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

pyodbc returns SQL Server DATE fields as strings

I'm using pyodbc to query a SQL Server 2008 database table with columns of DATE type. The resulting rows of data contain date strings rather than python datetime.date or datetime.datetime instances. This only appears to be an issue for columns of…
Daniel Fortunov
  • 43,309
  • 26
  • 81
  • 106
7
votes
2 answers

Passing table name as a parameter in pyodbc

I am trying to pass a table name in pyodbc as a parameter to access data from ms sql 2005. I've tried to substitute it with ? but it never works. I would be glad to receive any advice on how to accomplish this.
Siv Niznam
  • 161
  • 1
  • 3
  • 4
7
votes
1 answer

Communication link failure with pyodbc

import pyodbc import time connection = pyodbc.connect(..............) cursor = connection.cursor() while True: time.sleep(1) cursor.execute(INSERT_QUERY) cursor.commit() that works. but suddenly I got an exception pyodbc.Error:…
MicrosoctCprog
  • 460
  • 1
  • 3
  • 23
7
votes
3 answers

Handle TCP Provider: Error code 0x68 (104)

I'm using this code to sync my db with the clients: import pyodbc SYNC_FETCH_ARRAY_SIZE=25000 # define connection + cursor connection = pyodbc.connect() cursor = connection.cursor() query = 'select some_columns from…
Preston
  • 7,399
  • 8
  • 54
  • 84
7
votes
4 answers

RHEL 8 Container MSSQL ODBC Driver e2fsprogs

I'm trying to build a custom docker container using the RHEL 8 UBI. As part of this I want to install the MSSQL 17 ODBC driver. I've followed the steps outlined in Microsofts Documentation…
daark
  • 326
  • 3
  • 10
7
votes
2 answers

pyodbc operational error 08001 ssl security error

I am trying to connect to my database on MS SQL Server 2016 using pyodbc via the below python script from my laptop (on Windows 10) and planning to have the code deployed in a Linux RHEL 6.4 server. conn=pyodbc.connect('Driver={SQL Server};' …
Guna
  • 71
  • 2
  • 8
7
votes
2 answers

Pyodbc Drivers is Empty

Ok I've installed python3.8 on a mac, a number of odbcdrivers separately. I've created a new virtual environment and from within that environment run this: >>> import pyodbc >>> pyodbc.drivers() [] >>> I get this no matter where I run the command.…
A.Rowan
  • 1,460
  • 2
  • 16
  • 20
7
votes
3 answers

Is there any way to put timeout in pandas read_sql function?

I connect to a DB2 server through ODBC connection in my python code. The DB2 server gets reboot for maintainence or disconnects me while running specific server side tasks, happens 1 or 2 times in a day. At that time if my code has started executing…
Sumit Singh
  • 93
  • 1
  • 10
7
votes
1 answer

Efficient upsert of pandas dataframe to MS SQL Server using pyodbc

I'm trying to upsert a pandas dataframe to a MS SQL Server using pyodbc. I've used a similar approach before to do straight inserts, but the solution I've tried this time is incredibly slow. Is there a more streamlined way to accomplish an upsert…
ahh_real_numbers
  • 464
  • 3
  • 14
7
votes
1 answer

Linux Python Azure Function APP - pyodbc module not found despite being in requirements.txt and other modules working fine

I'm using a Linux consumption plan. I get the following error; Exception: ModuleNotFoundError: No module named 'pyodbc' I have added pyodbc in the requirements.txt file and other modules in this file such as azure-storage are working fine. Has…
David Hawkins
  • 1,049
  • 1
  • 10
  • 30
7
votes
1 answer

Slow loading SQL Server table into pandas DataFrame

Pandas gets ridiculously slow when loading more than 10 million records from a SQL Server DB using pyodbc and mainly the function pandas.read_sql(query,pyodbc_conn). The following code takes up to 40-45 minutes to load 10-15 million records from SQL…
Anjana Shivangi
  • 397
  • 2
  • 5
  • 19
7
votes
1 answer

Insert pandas dataframe created within Python into SQL Server

As referenced, I've created a collection of data (40k rows, 5 columns) within Python that I'd like to insert back into a SQL Server table. Typically, within SQL I'd make a 'select * into myTable from dataTable' call to do the insert, but the data…
Chris
  • 1,401
  • 4
  • 17
  • 28
7
votes
2 answers

Python - AttributeError: 'NoneType' object has no attribute 'cursor'

I have the following code: import pyodbc conn = pyodbc.connect('DSN=QueryBuilder') cursor = conn.cursor() stringA = "SELECT GrantInformation.Call FROM GrantInformation" cursor.execute(stringA) rows = cursor.fetchall() Its worked fine for years,…
Nicholas
  • 3,517
  • 13
  • 47
  • 86
7
votes
3 answers

Python 3.6 pyodbc to SQL How to execute SP

I've created a Python script to execute an SP using my cursor with connection odbc. I've tried everything I found but I can not execute the desired procedure. My code below: import pyodbc conn = pyodbc.connect( 'DRIVER={SQL Server};' …
Andres Urrego Angel
  • 1,842
  • 7
  • 29
  • 55
7
votes
1 answer

Pulling MS access tables and putting them in data frames in python

I have tried many different things to pull the data from Access and put it into a neat data frame. right now my code looks like this. from pandas import DataFrame import numpy as np import pyodbc from sqlalchemy import create_engine db_file =…
michaelg
  • 243
  • 2
  • 8
  • 25