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
1
vote
0 answers

threading error when calling pyodbc cursor

I am receiving "TypeError: bad argument type for built-in operation" error when calling cursor.columns from pyodbc, Traceback the issue to threading.py -> currentThread function... I have installed my python environment on a new HP Z2 desktop PC…
Daniel Sapir
  • 23
  • 1
  • 4
1
vote
2 answers

Sanitized queries in pyodbc returns only the field name

When I query my SQL server with pyodbc, I get only the name of the field I requested (instead of the values itself). import pyodbc conn = pyodbc.connect(connection_string) cursor = conn.cursor() cursor.execute('SELECT ? FROM [Projects]',…
joedeandev
  • 626
  • 1
  • 6
  • 15
1
vote
1 answer

Refreshing dataframe in Python inside a While loop

I have a data frame that fetches data from SQL and sends out an email based on the condition of a column. But these columns are not present in SQL, I need to create them after creating the data frame. The issue here is I have a while loop where it…
Krishnamurthy
  • 139
  • 2
  • 8
1
vote
1 answer

Using pythonanywhere's MySQL DB in python

I've created a MySQL DB on pythonanywhere.com. Now I'm writing a python script on my local PC trying to connect to it, but can't establish a connection. import pyodbc with pyodbc.connect(DRIVER="{MySQL ODBC 8.0 Unicode Driver}", …
Manuel
  • 31
  • 3
1
vote
2 answers

Why does SQL Server return numbers like 0.759999 while MySQL returns 0.76?

I have a SQL Server database table which has three columns. As an example, one of the values in this column might be 0.76. This column of data, named 'paramvalue' is defined as real. When I use the pyodbc module command fetchall() I get back a…
timothyjb
  • 35
  • 6
1
vote
2 answers

Trying to insert a record into SQL Server with pyodbc and tkinter

I am trying to write an application that will easily update a database when new equipment is added. So far I am able to connect to db and have created a GUI to show a few things. Now I am stuck at trying to insert a new record from an entry that a…
jellisee
  • 13
  • 1
  • 3
1
vote
1 answer

PYODBC Inserting data into datetime column produces incorrectly formatted table

I am currently writing a program that will take data from an excel spreadsheet and insert it into a sql server table that I have created within the program. I have previously assigned the datetime column to be a nvarchar(250) for the purpose of…
Mattidge
  • 83
  • 8
1
vote
1 answer

Parameters in pyodbc in pandas read_sql_query

Given the following query string, symbol = "'AAPL'" query = """SELECT TOP (1000000) [date] ,[symbol] ,[open] ,[high] ,[low] ,[close] ,[volume] ,[exch] FROM [AMEXEOD].[dbo].[Stocks_eod] …
Ivan
  • 7,448
  • 14
  • 69
  • 134
1
vote
1 answer

how to insert multiple rows from list with Python

I am trying to figure out how to insert multiple rows into python but I get an error: TypeError: ('Params must be in a list, tuple, or Row', 'HY000') for folderName in os.listdir(parentDirectory): for fileName in…
donL
  • 1,290
  • 3
  • 13
  • 37
1
vote
1 answer

ODBC Connection to Access 2016 Failing from Python with pyodbc

My code: connection_string = (r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\\Users\\Bob-Admin\\Documents\\MyDatabase.accdb;') cnxn = pyodbc.connect(connection_string, autocommit=True) crsr = cnxn.cursor() My error: ('IM002', '[IM002]…
Justin
  • 65
  • 5
1
vote
1 answer

Update query using python odbc cursor - Not working

I have this query executed with the following snippet: cursor2.execute("UPDATE datatable SET data1 = ?, data2 = ?, data3 = ? WHERE id = ?",[d1,d2,d3,i]) print("affected rows = {}".format(cursor2.rowcount)) Affected rows returns 1 but row in…
Rav
  • 1,327
  • 3
  • 18
  • 32
1
vote
1 answer

Importing database takes a lot of time

I am trying to import a table that contains 81462 rows in a dataframe using the following code: sql_conn = pyodbc.connect('DRIVER={SQL Server}; SERVER=server.database.windows.net; DATABASE=server_dev; uid=user; pwd=pw') query = "select * from…
Questieme
  • 913
  • 2
  • 15
  • 34
1
vote
2 answers

When testing my aws lambda getting error:- "Unable to import module 'app': No module named 'pyodbc'",

pyodbc is included in zip but still giving error when trying to test the lambda function. Installed pyodbc using pip3 and included the lib file while creating the lambda zip. import logging import rds_config import pyodbc # import requests #rds…
dkm007
  • 145
  • 2
  • 6
1
vote
1 answer

Issue with building JSON format. Choose between dict and collections?

I'm building json format and the expected is as below: { accounts:[ { "acctnum": "acct1", "key2":"value2" "key3": [] "summary" : { //nested dict } } ] //if we have 1 account for given customer …
more09
  • 57
  • 1
  • 7
1
vote
0 answers

Delete rows with pyodbc freezes and doesn't delete rows

I am writing a script to remove rows from a SQL Azure database. When I execute this script in Jupyter notebook it runs forever and never deletes the rows. Any ideas why this script is not executing? key = input("Enter key to remove\n") cnxn =…
Rubiks
  • 461
  • 1
  • 6
  • 21