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

Pyodbc - SQL Truncating Parameters

I am passing about 80k parameters but while executing the query, it seems like pyodbc or SQL is truncating the total number of parameters. It works when I pass around 2k parameters but fails anything above 2k. Below is my queries and I will highly…
Krishnang K Dalal
  • 2,322
  • 9
  • 34
  • 55
1
vote
1 answer

Unable to perform like query with parameter using pyodbc

I'm trying to pass a variable as a parameter in an access query so I can generate a list of similar names on my website. I'm using pyodbc to access a .mdb database for my flask app. I tried passing a variable in many ways like... xyz =…
1
vote
1 answer

UPDATE statement pyodbc set NULL value (instead of None) in sql server

I have code where I want to update certain entries in a database. Some attributes can have a NULL value. Let's look at following situation: new_doc_name = doc_name (can be None or string value) sql = UPDATE Documents SET DocName = new_doc_name…
aze45sq6d
  • 876
  • 3
  • 11
  • 26
1
vote
1 answer

How would I create a PostgreSQL database using "CREATE DATABASE" over an ODBC connection using PyODBC?

I am attempting to create a PostgreSQL 12.1 database (not a schema) using the CREATE DATABASE statement from a Python 3.7.5 program connecting to a PostgreSQL 12.1 instance as user postgres over UnixODBC and using the PyODBC module, all running on…
Michael G. Morey
  • 318
  • 1
  • 5
  • 13
1
vote
1 answer

How to retry after sql connection failed in python?

Whats the right way to retry when connection/write to a DB fails in python? Im trying to use this code and it works until i restart my sql server and python tries to connect to it i get "retry after 30 sec" for 10 times with 30 secs intervalls but…
Oscar Larsson
  • 83
  • 1
  • 10
1
vote
0 answers

Pyodbc - SQL Injection in Upsert

I have used ? placeholder to pass list of values in Python for Insert/Update. Now, I am trying to upsert the records with the help of this answer Code: table_name = 'ddf.ddf_actuals' columns_list = df.columns.tolist() columns_list_query =…
Karthick Raju
  • 757
  • 8
  • 29
1
vote
0 answers

image insert to SQL Server varbinary(max) gets truncated to 8kb

I'm trying to upload high resolution images though pyodbc 4.0.30 to my database using a filestream. INSERT INTO images(id, imageFile) SELECT NEWID(), BulkColumn FROM OPENROWSET(BULK 'd:/tmp/20150627_132729.jpg', SINGLE_BLOB) as f; This code…
Zain
  • 11
  • 3
1
vote
2 answers

pandas.read_sql_query() throws TypeError: 'NoneType' object is not iterable

I am using pandas.read_sql_query function to read from a few sql files. One query throws an error at one particular bit which I have singled out. (python bit - nothing exotic and works with other queries) @contextmanager def…
semiarty
  • 21
  • 3
1
vote
1 answer

How does the pymssql library fall back on the named pipe port when port 1433 is closed?

I'm trying to remove pymssql and migrate to pyodbc on a python 3.6 project that I'm currently on. The network topology involves two machines that are both on the same LAN and same subnet. The client is an ARM debian based machine and the server is a…
Daniel Caban
  • 111
  • 1
  • 3
1
vote
2 answers

Dataframe with a single Column Value

I'm using pyodbc to get the data out of a pervasive database. import pyodbc import pandas as pd conn_str = "Driver={Pervasive ODBC Client Interface};ServerName=SC220;DBQ=RDP51" db = pyodbc.connect(conn_str) c = db.cursor() sql = "select * from…
SpencerRDP
  • 11
  • 2
1
vote
1 answer

Too few parameters error using pyodbc on a query containing a hardcoded where clause?

I've seen several questions about the "Too Few Parameters" error but have not found one that quite matches my situation. Simplified code: db.cursor.execute ('''SELECT [PT_NUMBER] FROM [newtest1];''') newtest1 is a saved MS Access query containing a…
eep
  • 53
  • 7
1
vote
0 answers

pyodbc with Azure SQL Server, String or binaray data would be truncated. (8152)

I am very much aware of what this issue normally signifies and typical troubleshooting steps. Before you immediately link me to another solution please read the following details: My database column I am inserting into is sized varchar(max) as…
1
vote
1 answer

[SQL Server]Statement(s) could not be prepared

here's my code import pyodbc username = 'abcdefg' newPassword = 'xyz1234!' cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=abc.database.windows.net;DATABASE=master;UID=yyzzyy;PWD=abcd1234!') cursor = cnxn.cursor() cursor.execute("ALTER LOGIN ?…
Kuldeep
  • 23
  • 2
  • 8
1
vote
0 answers

Pyodbc connection error encoding name too long

I use pyodbc to connect into a postgresql server over an ssh connection, the ssh connection goes well, but when I try to connect to the bd its returns a strange error: encoding name too long I don't know how to handle this! Conn string -…
Guilherme Cesar
  • 113
  • 1
  • 1
  • 7
1
vote
2 answers

Unable to connect to Azure SQL Database via Python ODBC Driver Issue

I am trying to connect to azure sql database. But somehow I keep getting the following error: pyodbc.OperationalError: ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]Client unable to establish connection (0) …