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
2 answers

Is it possible to specify the driver dll directly in the ODBC connection string?

I'm trying to use pyodbc to connect to a SQL Server (MS SQL Server through FreeTDS) in a portable application; since it's supposed to be standalone, I would like to avoid having to explicitly install the driver on the system, just bringing the ODBC…
Matteo Italia
  • 123,740
  • 17
  • 206
  • 299
7
votes
2 answers

Speed up inserts into SQL Server from pyodbc

In python, I have a process to select data from one database (Redshift via psycopg2), then insert that data into SQL Server (via pyodbc). I chose to do a read / write rather than a read / flat file / load because the row count is around 100,000…
mikebmassey
  • 8,354
  • 26
  • 70
  • 95
7
votes
2 answers

How to return errors from PYODBC

I'm making a connection to SQL Server to execute a stored procedure. What is the correct way to 'poll' the server to determine whether the stored procedure finished running successfully or returned an error if the SP takes longer than 60 seconds /…
mikebmassey
  • 8,354
  • 26
  • 70
  • 95
7
votes
2 answers

Pyodbc- If table exist then don't create in SSMS

I am trying something like: import pyodbc cnxn = pyodbc.connect(driver ='{SQL Server}' ,server ='host-MOBL\instance',database ='dbname', trusted_connection = 'yes' ) cursor = cnxn.cursor() cursor.execute("""SELECT * FROM INFORMATION_SCHEMA.TABLES…
Dsw Wds
  • 482
  • 5
  • 17
7
votes
2 answers

What's the cause of this UnicodeDecodeError with an nvarchar field using pyodbc and MSSQL?

I can read from a MSSQL database by sending queries in python through pypyodbc. Mostly unicode characters are handled correctly, but I've hit a certain character that causes an error. The field in question is of type nvarchar(50) and begins with…
vowel-house-might
  • 1,686
  • 14
  • 18
7
votes
1 answer

How to use windows authentication to connect to MS SQL server from windows workstation in another domain with Python

I'm trying to connect to SQL server 2000 installed on Windows server 2003 from Windows Server 2008 R2 using Python 3.4 and pyodbc module. Those servers are in different AD domains. Windows only authentication is enabled on SQL server and I can't…
Andrey Grachev
  • 1,259
  • 1
  • 14
  • 22
7
votes
1 answer

Connect to SQL Server using SQLAlchemy

I'm trying to connect to a SQL Server Express database using SQLALchemy and pyodbc, but I'm continuously getting the error: (pyodbc.Error) ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified…
daveoncode
  • 18,900
  • 15
  • 104
  • 159
7
votes
1 answer

sql server function native parameter bind error

I'm using the following software stack on Ubuntu 10.04 Lucid LTS to connect to a database: python 2.6.5 (ubuntu package) pyodbc git trunk commit eb545758079a743b2e809e2e219c8848bc6256b2 unixodbc 2.2.11 (ubuntu package) freetds 0.82 (ubuntu…
nosklo
  • 217,122
  • 57
  • 293
  • 297
7
votes
2 answers

How convert None to NULL with Python 2.7 and pyodbc

I am passing the output from a sql query to again insert the data to ms sql db. If my data is null python / pyodbc is returning None instead of NULL. What is the best way to convert None to NULL when I am calling another query using the same…
Shakti
  • 2,013
  • 8
  • 27
  • 40
7
votes
1 answer

how connect to vertica using pyodbc

I've read the iODBC documentation regarding the odbc.ini, and the Vertica documentation. I also saw a question with the same error, but can't get the connection string to work as suggested in the previous question's answer. What I currently…
Kermit
  • 33,827
  • 13
  • 85
  • 121
7
votes
1 answer

MS SQL Invalid Object Name

I have cursor.execute("select RM_ID FROM Sales.dbo.MARKETING where VERSION = 'SomeVersion'") which gives me the traceback error: pyodbc.ProgrammingError: ('42S02', "[42S02] [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name…
James.Wyst
  • 859
  • 3
  • 8
  • 13
7
votes
2 answers

Writing unicode strings to Excel 2007

I am connecting to a MS SQL server using pyodbc. Furthermore, I am trying to write to an Excel 2007/10 .xlsx file using openpyxl. This is my code (Python 2.7): import pyodbc from openpyxl import Workbook cnxn = pyodbc.connect(host =…
Rym
  • 143
  • 1
  • 7
7
votes
3 answers

Reading DBF files with pyodbc

In a project, I need to extract data from a Visual FoxPro database, which is stored in dbf files, y have a data directory with 539 files I need to take into account, each file represents a database table, so I've been doing some testing and my code…
iferminm
  • 2,019
  • 19
  • 34
7
votes
2 answers

sql print statements from pyodbc

How do I get the output from the sql_query? import pyodbc sql_query = "print 'Hello World'" conn = pyodbc.connect("DRIVER={SQL Server}; SERVER=myserver; DATABASE=mydatabase; UID=myusername; PWD=mypassword") cur =…
ijk
  • 175
  • 1
  • 7
7
votes
1 answer

Inserting pyodbc.Binary data (BLOB) into SQL Server image column

I am trying to insert binary data into a column of image datatype in a SQL Server database. I know varbinary(max) is the preferred data type, but I don't have rights to alter the schema. Anyhow, I am reading the contents of a file and wrapping it in…
slachterman
  • 1,515
  • 4
  • 17
  • 23