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

SQL server, pyodbc and deadlock errors

I have some code that writes Scrapy scraped data to a SQL server db. The data items consist of some basic hotel data (name, address, rating..) and some list of rooms with associated data(price, occupancy etc). There can be multiple celery threads…
fpghost
  • 2,834
  • 4
  • 32
  • 61
9
votes
2 answers

Pyodbc installation error on Ubuntu 16.04 with Sql Server installed

I am trying to test my scripts for data migration from mssql-server to oracle server. For this, I have to install pyodbc python package for Ubuntu, it has the dependency of unixodbc. When I try to install unixodbc-dev using: sudo apt-get install…
Shubham Namdeo
  • 1,845
  • 2
  • 24
  • 40
9
votes
1 answer

ODBC Driver 13 for SQL Server can't open lib on pyodbc while connecting on AWS E2 ubuntu instance

Background: i have been at it for about a week but still no luck. the same driver (13.0) on my system (Ubuntu 16.04.1 LTS) works just fine with my pyodbc python (Python 2.7.12 :: Anaconda 4.1.1 (64-bit)) library. i tried setting up a virtual…
9
votes
3 answers

Cannot import pyodbc on Mac

I am unable to import pyodbc on my Macbook Pro (running Mac OS X 10.10.5) and python version 2.7.10. I used pip to get it, and I have the latest version (3.0.10). It gives me the following error: $ python Python 2.7.10 (default, Jul 14 2015,…
Turix
  • 4,470
  • 2
  • 19
  • 27
9
votes
1 answer

pyodbc on SQL Server - How can I do an insert and get the row ID back?

I'm using pyodbc with SQL Server 2000. I want to be able to insert a row and get the auto incremented row id value back? Any ideas? Here's what I have so far: cursor.execute("insert into products(id, name) values ('pyodbc', 'awesome…
Greg
  • 45,306
  • 89
  • 231
  • 297
9
votes
1 answer

Connecting to MS SQL Server with iODBC on Mac

I'm trying to connect to a Microsoft SQL Server from my Mac development machine using iODBC. No matter what I do, I get the error message Unable to connect to data source from the FreeTDS driver. After consulting various manuals, blog posts, and…
josePhoenix
  • 538
  • 1
  • 5
  • 14
8
votes
4 answers

How to get a SQL Server stored procedure return value using pyodbc?

My team's using a python-based wiki server that calls stored procedures on a SQL Server database. Ideally, we'd like to return integer values (1,0,-1) from the stored procedure to show basic results. According to a 2008 thread on Google Groups,…
Matthew Glidden
  • 382
  • 2
  • 6
  • 15
8
votes
2 answers

PyODBC outputting improper UTF-16

I'm trying to pull out a list of table names from a MySQL database. The pertinent parts of the code are as follows: conn = pyodbc.connect('...') cursor = conn.cursor() for table in cursor.tables(): print table.table_name For every table it…
Jonathan
  • 1,050
  • 1
  • 12
  • 36
8
votes
2 answers

pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near

I'm using python 3.9 to insert a list of multiple news from google rss news to SQL table with parameter using pyobc but always getting programming error below: cursor.execute(query) pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC SQL…
Ng Hà
  • 81
  • 1
  • 1
  • 4
8
votes
3 answers

SQLAlchemy error: An attempt to complete a transaction has failed. No corresponding transaction found

I have installed: Ubuntu (18.04) Python (3.6.8) msodbcsql17 (Microsoft ODBC Driver 17 for SQL Server) SQLAlchemy (1.3.5) Pandas (0.24.2) and I want to create just a proof of concept using SQLAlchemy with an Azure SQL Data Warehouse. However, when…
8
votes
2 answers

How to return a list from SQL query using pyodbc?

I am trying to run a select query to retrieve data from SQL Server using pyodbc in python 2.7. I want the data to be returned in a list. The code I have written is below. It works, kinda, but not in the way I expected. My returned list looks…
mHelpMe
  • 6,336
  • 24
  • 75
  • 150
8
votes
2 answers

Multithreaded pyodbc connection

I am trying to use a pyodbc connection in multiple threads. I am receieving the following error: Connection is busy with results for another command (0) (SQLExecDirectW)'). I also tried setting MultipleActiveResultSets=yes; and got the same results.…
J. Darnell
  • 519
  • 7
  • 15
8
votes
4 answers

UnicodeDecodeError: 'utf-16-le'

I'm trying to pull a list of tables from an access database. The script goes through and displays about a third of the tables and gets the following error: Traceback (most recent call last): File "C:/GageInfo/sourcecode for …
Eddie Snipes
  • 119
  • 1
  • 1
  • 8
8
votes
3 answers

DatabaseError: ('HY000', '[HY000] [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt (0) (SQLExecDirectW)')

I am trying to read data from SQL server into pandas data frame. Below is the code. def get_data(size): con = pyodbc.connect(r'driver={SQL Server}; server=SPROD_RPT01; database=Reporting') cur = con.cursor() db_cmd = "select distinct top…
Krishnang K Dalal
  • 2,322
  • 9
  • 34
  • 55
8
votes
2 answers

Have pyodbc return a simple (scalar) value for a query that only returns one item

I am having an issue when I select data from the SQL database through pyodbc where I end up with this type of result. [(55.0, )] I want the pure number (no "[" or "(" so I later can insert it into a different table after calculating new stuff with…
MathiasRa
  • 825
  • 2
  • 12
  • 24