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
21
votes
7 answers

Writing a csv file into SQL Server database using python

I am trying to write a csv file into a table in SQL Server database using python. I am facing errors when I pass the parameters , but I don't face any error when I do it manually. Here is the code I am executing. cur=cnxn.cursor() # Get the…
NG_21
  • 685
  • 2
  • 13
  • 22
20
votes
1 answer

Does pyodbc support any form of named parameters?

I know sqlite3 has data = {'test_col': 012345679} sqlite3_conn.execute(""" UPDATE test_db SET test_col = :test_col ;""", data) and mysql-connector-python has data = {'test_col': 012345679} mysql_conn.execute(""" UPDATE test_db SET…
randomdev2
  • 315
  • 1
  • 2
  • 7
20
votes
1 answer

python pyodbc : how to connect to a specific instance

Am trying to connect to a specific instance of SQL Server and get some data from system tables. Am connecting using this code snippet: connSqlServer = pyodbc.connect('DRIVER={SQL Server Native Client…
Jean
  • 2,611
  • 8
  • 35
  • 60
20
votes
7 answers

Cannot establish connection to sql-server using pyodbc on Windows 7

I'm using ActivePython 2.7.2.5 on Windows 7. While trying to connect to a sql-server database with the pyodbc module using the below code, I receive the subsequent Traceback. Any ideas on what I'm doing wrong? CODE: import pyodbc driver = 'SQL…
nicholsonjf
  • 971
  • 2
  • 11
  • 21
20
votes
2 answers

pyodbc.connect timeout argument is ignored for calls to SQL Server

I am using pyodbc on Linux with FreeTDS to connect to SQL Server 2005. I have noticed that the timeout argument to my connection is not being honoured by my queries. When I run the following I would expect to see timeout errors after both…
ChrisGuest
  • 3,398
  • 4
  • 32
  • 53
19
votes
3 answers

pyodbc and python 3.4 on Windows

pyodbc is a very nice thing, but the Windows installers only work with their very specific python version. With the release of Python 3.4, the only available installers just stop once they don't see 3.3 in the registry (though 3.4 is certainly…
steegness
  • 459
  • 1
  • 4
  • 10
18
votes
4 answers

How to get the IDENTITY value when using INSERT ... OUTPUT with pyodbc

I am trying to get the ID of a newly inserted row by using OUTPUT. However, I encountered the HY010 error. The following query/code is what I use: string = """ SET NOCOUNT ON; DECLARE @NEWID TABLE(ID INT); INSERT INTO…
Alex
  • 4,030
  • 8
  • 40
  • 62
18
votes
4 answers

"Invalid parameter type" (numpy.int64) when inserting rows with executemany()

I try to insert bunch of data to database insert_list = [(1,1,1,1,1,1),(2,2,2,2,2,2),(3,3,3,3,3,3),....] #up to 10000 tuples in this list conn = pyodbc.connect('DRIVER={FreeTDS};SERVER=xxxxx;DATABASE=xxxx;UID=xx;PWD=xx;TDS_Version=7.0') cursor =…
YONG BAGJNS
  • 501
  • 2
  • 8
  • 21
18
votes
1 answer

Connect pyodbc to Postgres

Trying to connect to Postgres using pyodbc. I can connect to the DB with isql: echo "select 1" | isql -v my-connector Returns: +---------------------------------------+ | Connected! | | …
Christopher Carlson
  • 963
  • 2
  • 10
  • 20
18
votes
1 answer

Python Connection to Hive

I installed the Hortonworks Hive ODBC driver and created a connection in the Data sources. I tested it and it worked successfully. I installed PyODBC and wrote the following code import os, sys, pyodbc; con = pyodbc.connect("DSN=MyCon") I got…
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
18
votes
2 answers

Function sequence error in PYODBC

I am using pyodbc to connect to a database and extract certain data from it. Here is my code: con = pyodbc.connect("driver={SQL Server};server= MyServer;database= MyDatabase;trusted_connection=true") cursor = con.cursor() SQL_command = """ …
ChangeMyName
  • 7,018
  • 14
  • 56
  • 93
18
votes
1 answer

does pyodbc have any design advantages over pypyodbc?

I know pyodbc is an older project and probably more featureful and robust, but is there anything about its design (based on components of compiled C code), that would make it preferable to a pure Python implementation, such as pypyodbc? I do a lot…
Tony
  • 625
  • 1
  • 6
  • 17
17
votes
3 answers

import pyodbc failure mac os

I've tried to install pyodbc on mac, but I got this error Traceback (most recent call last): File "Untitled.py", line 1, in import pyodbc ImportError: dlopen(/usr/local/lib/python3.6/site-packages/pyodbc.cpython-36m-darwin.so, 2):…
volkoshkursk
  • 325
  • 1
  • 2
  • 14
17
votes
5 answers

pyodbc the sql contains 0 parameter markers but 1 parameters were supplied' 'hy000'

I am using Python 3.6, pyodbc, and connect to SQL Server. I am trying make connection to a database, then creating a query with parameters. Here is the code: import sys import pyodbc # connection parameters nHost = 'host' nBase = 'base' nUser =…
Aleks
  • 419
  • 1
  • 5
  • 16
17
votes
6 answers

Error "Previous SQL was not a query" in Python?

I am trying to call a stored procedure in Python but it keeps giving me the following error. The procedure is written in SQL Server 2008 and I am using PyODBC to call the method and pass parameters to it. import pyodbc cnxn =…
user7135817