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

pyodbc insert into sql

I use a MS SQL express db. I can connect and fetch data. But inserting data does not work: cursor.execute("insert into [mydb].[dbo].[ConvertToolLog] ([Message]) values('test')") I get no error but nothing is inserted into the table. Directly after…
daniel
  • 34,281
  • 39
  • 104
  • 158
54
votes
11 answers

MSSQL2008 - Pyodbc - Previous SQL was not a query

I can't figure out what's wrong with the following code, The syntax IS ok (checked with SQL Management Studio), i have access as i should so that works too.. but for some reason as soon as i try to create a table via PyODBC then it stops…
Torxed
  • 22,866
  • 14
  • 82
  • 131
52
votes
7 answers

Using Sql Server with Django in production

Has anybody got recent experience with deploying a Django application with an SQL Server database back end? Our workplace is heavily invested in SQL Server and will not support Django if there isn't a sufficiently developed back end for it. I'm…
Josh Smeaton
  • 47,939
  • 24
  • 129
  • 164
49
votes
6 answers

Pyodbc - "Data source name not found, and no default driver specified"

I have trouble getting pyodbc work. I have unixodbc , unixodbc-dev, odbc-postgresql, pyodbc packages installed on my Linux Mint 14. I am losing hope to find solution on my own, any help appreciated. See details below: Running: >>> import pyodbc >>>…
user1841829
47
votes
6 answers

How to speed up bulk insert to MS SQL Server using pyodbc

Below is my code that I'd like some help with. I am having to run it over 1,300,000 rows meaning it takes up to 40 minutes to insert ~300,000 rows. I figure bulk insert is the route to go to speed it up? Or is it because I'm iterating over the…
TangoAlee
  • 1,260
  • 2
  • 13
  • 34
40
votes
9 answers

Get data from pandas into a SQL server with PYODBC

I am trying to understand how python could pull data from an FTP server into pandas then move this into SQL server. My code here is very rudimentary to say the least and I am looking for any advice or help at all. I have tried to load the data…
andy redmayne
  • 403
  • 1
  • 4
  • 6
39
votes
11 answers

Connect docker python to SQL server with pyodbc

I'm trying to connect a pyodbc python script running in a docker container to login to a MSSQL database I have tried all sorts of docker files, but not been able to make the connection (fails when bulding the docker or when python tries to connect),…
Kåre Rasmussen
  • 863
  • 1
  • 8
  • 16
39
votes
13 answers

Installing pyodbc fails on OSX 10.9 (Mavericks)

When running pip install pyodbc, I get In file included from .../build/pyodbc/src/buffer.cpp:12: .../build/pyodbc/src/pyodbc.h:52:10: fatal error: 'sql.h' file not found #include ^ 1 error generated. error:…
Moshe
  • 2,638
  • 2
  • 28
  • 32
33
votes
7 answers

Using SQL Server stored procedures from Python (pyodbc)

I'm have a stored procedure, code: DECLARE @RC int DECLARE @id varchar(13) DECLARE @pw varchar(13) DECLARE @depart varchar(32) DECLARE @class varchar(12) DECLARE @name varchar(12) DECLARE @birthday varchar(10) DECLARE @grade int DECLARE…
bartezr
  • 727
  • 3
  • 10
  • 26
30
votes
7 answers

how to catch specific pyodbc error message

I trid the following code, import pyodbc try: pyodbc.connect('DRIVER={%s};SERVER=%s;DATABASE=%s;UID=%s;PWD=%s' % (driver, server, database, uid, password)) except pyodbc.Error, err: logging.warn(err) The error message format i get is…
ashokadhikari
  • 1,182
  • 3
  • 15
  • 29
29
votes
4 answers

Pyodbc error Data source name not found and no default driver specified paradox

I am attempting to use pyobdc to read data from a paradox database, and I keep getting the following error when attempting to connect to the database: pyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and…
Marcello B.
  • 4,177
  • 11
  • 45
  • 65
29
votes
6 answers

Python pip unable to locate pyodbc

Using virtualenv and just trying to install pyodbc. All resources I can find claim this should be extremely straightforward. After all the basic installs of MySQL, etc., just do: pip install pyodbc However, I am seeing a very strange error. It has…
ely
  • 74,674
  • 34
  • 147
  • 228
28
votes
5 answers

SqlAlchemy equivalent of pyodbc connect string using FreeTDS

The following works: import pyodbc pyodbc.connect('DRIVER={FreeTDS};Server=my.db.server;Database=mydb;UID=myuser;PWD=mypwd;TDS_Version=8.0;Port=1433;') The following fails: import…
mwolfe02
  • 23,787
  • 9
  • 91
  • 161
27
votes
13 answers

What's causing 'unable to connect to data source' for pyodbc?

I'm trying to connect to an MSSQL database from python on Linux (SLES). I have installed pyodbc and Free TDS. From the command line: tsql -H server -p 1433 -U username -P password Connects to the server without a problem, however, from…
pbaehr
  • 622
  • 1
  • 5
  • 11
27
votes
5 answers

Pyodbc: Login Timeout Error

I am trying to connect to MS SQL Server using pyodbc from a remote machine running Ubuntu 16.04. import pyodbc conn = pyodbc.connect(r'DRIVER=ODBC Driver 17 for SQL Server; SERVER=xxxTest-SRV; PORT=51333; DATABASE=TestDB; UID=xxxx;…
Krishnang K Dalal
  • 2,322
  • 9
  • 34
  • 55