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
11
votes
4 answers

pyodbc + MySQL + Windows: Data source name not found and no default driver specified

I am trying to connect to MySQL 5.6 on a Windows Server 2008 R2 localhost with pyodbc. I used the full installation for the MySQL instance on the localhost, including the ODBC connector. I have it connecting to a remote SQL Server instance…
sct.chang
  • 121
  • 1
  • 1
  • 4
11
votes
3 answers

Inserting datetime into a MS SQL table using pyodbc

I'm trying to insert a datetime value into a MS SQL Server table using pyodbc. If I do it manually, something like: cursor.execute("""insert into currentvalue(value1,currentdatetime) values(55,'2014-06-27…
user3784140
  • 111
  • 1
  • 1
  • 3
11
votes
1 answer

How to set a DB connection timeout for a python/pyodbc/unixODBC/MS ODBC Driver 11 for SQL Server/Linux stack?

I've been unable to find a documented way to set a timeout for the initial connection that actually works. I'm not asking about a "query timeout", but rather a timeout on an initial connection attempt in the case that the DB server is completely…
mikenerone
  • 1,937
  • 3
  • 15
  • 19
11
votes
3 answers

Follow up: Execute .sql files from python

Over a year ago someone asked this question: Execute .sql files that are used to run in SQL Management Studio in python. I am writing a script in python that connects to a SQL server and creates and populates a database based on SQL commands in a…
Neal Kruis
  • 2,055
  • 3
  • 26
  • 49
10
votes
2 answers

unable to install pyodbc using python 3.10 in windows 10

I get this Error when I try to install Pyodbc , I have already install visual studio and I have Microsoft Visual C++ 12 , 15-19 in my machine but still its giving this error. Running setup.py clean for pyodbc Failed to build pyodbc Installing…
umair mehmood
  • 529
  • 2
  • 5
  • 17
10
votes
2 answers

Do you know how to install the 'ODBC Driver 17 for SQL Server' on a Databricks cluster?

I'm trying to connect from a Databricks notebook to an Azure SQL Datawarehouse using the pyodbc python library. When I execute the code I get this error: Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL…
user2364105
  • 138
  • 1
  • 1
  • 6
10
votes
3 answers

SystemError: returned a result with an error set

def insert(self): conn = pyodbc.connect( 'Driver={SQL Server};' 'Server=DESKTOP-S0VG212\SQLEXPRESS;' 'Database=MovieGuide;' 'Trusted_Connection=yes;' ) cursor = conn.cursor() Error occurs when executing…
Abubakar Soomro
  • 121
  • 1
  • 1
  • 6
10
votes
3 answers

Cannot open server requested by the login

I'm trying to connect to my Azure SQL database using pyodbc. The azure account that I am using is under the username xxxxxx@student.bham.ac.uk (my university account). When I try to connect to the database, I get the error Cannot open server…
Hdot
  • 543
  • 1
  • 4
  • 15
10
votes
0 answers

Using PYODBC from Windows WSL

I am using Windows WSL and am trying to configure python to connect to MSSQL I have installed…
khinester
  • 3,398
  • 9
  • 45
  • 88
10
votes
1 answer

In Python, Is it possible to connect Azure SQL Server using Active Directory Password Authentication?

I have tried to connect sql server using pyodbc library, driver= '{ODBC Driver 17 for SQL Server}' cnxn = pyodbc.connect('DRIVER='+driver+';SERVER='+host+';PORT=1443;DATABASE='+database+';UID='+user+';PWD='+…
user1023514
  • 101
  • 1
  • 1
  • 4
10
votes
1 answer

Importing data from an excel file using python into SQL Server

I have found some other questions that have a similar error to what I am getting, but have not been able to figure out how to resolve this based on the answers. I am trying to import an excel file into SQL Server with the help of python. This is the…
bernando_vialli
  • 947
  • 4
  • 12
  • 27
10
votes
2 answers

ODBC SQL type -155 is not yet supported

I follow this link to query Azure database. import pyodbc server = 'your_server.database.windows.net' database = 'your_database' username = 'your_username' password = 'your_password' driver= '{ODBC Driver 13 for SQL Server}' cnxn =…
Sam
  • 1,252
  • 5
  • 20
  • 43
10
votes
1 answer

"CREATE ... statement not allowed within multi-statement transaction" when using pyodbc

I'm trying to create a SQL Server database using pyodbc. import pyodbc server = 'AMR112\NAMED1' database = 'msdb' username = '' password = 'mypassword' abcd='yes' ghi='False' #driver = '{/usr/local/lib/libtdsodbc.so}' #for linux of windows…
userbb
  • 121
  • 1
  • 5
10
votes
1 answer

Reading from SQL Server with params: pandas (or pyodbc) not functioning properly

I'm using a query in SQL Server that requires a range to check whether a number is in that range (e.g. in the below to check if DemographicGroupDimID is either (1,2 or 3) . After doing some googling the only way I found to be able to do that was the…
mburke05
  • 1,371
  • 2
  • 25
  • 38
10
votes
2 answers

Pyodbc - print first 10 rows (python)

I'm trying to print the first 10 rows using pyodbc. I know how to get the first record by using the following: row = cursor.fetchall() I tried changing this to: row = cursor.fetchten() but this didn't work. Is there anything else I can do??
semiflex
  • 1,176
  • 3
  • 25
  • 44