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

How to check version of python package if no __version__ variable is set

I am using pyodbc and I want to know the version of it that I am using. Apparently I cannot use pyodbc.__version__ because probably the variable is not set. How else can I figure out the version of the package?
LetsPlayYahtzee
  • 7,161
  • 12
  • 41
  • 65
17
votes
4 answers

Read stored procedure select results into pandas dataframe

Given: CREATE PROCEDURE my_procedure @Param INT AS SELECT Col1, Col2 FROM Table WHERE Col2 = @Param I would like to be able to use this as: import pandas as pd import pyodbc query = 'EXEC my_procedure @Param =…
joeb1415
  • 527
  • 2
  • 7
  • 12
17
votes
3 answers

Getting Table and Column names in PyOdbc

I'd like to retrieve the fully referenced column name from a PyOdbc Cursor. For example, say I have 2 simple tables: Table_1(Id, < some other fields >) Table_2(Id, < some other fields >) and I want to retrieve the joined data select * from…
Brad
  • 1,367
  • 1
  • 8
  • 17
17
votes
2 answers

In Python, Using pyodbc, How Do You Perform Transactions?

I have a username which I must change in numerous (up to ~25) tables. (Yeah, I know.) An atomic transaction seems to be the way to go for this sort of thing. However, I do not know how to do this with pyodbc. I've seen various tutorials on…
MetaHyperBolic
16
votes
3 answers

pyodbc/FreeTDS/unixODBC on Debian Linux: issues with TDS Version

I'm having a bit of trouble successfully using pyodbc on Debian Lenny (5.0.7). Specifically, I appear to be having trouble fetching NVARCHAR values (not a SQL Server expert, so go easy on me :) ). Most traditional queries work OK. For instance, a…
tcdyl
  • 325
  • 2
  • 13
16
votes
1 answer

BULK INSERT error code 3: The system cannot find the path specified

I am trying to bulk insert a local file into a remote MS_SQL database using pyodbc. I am able to connect to the DB and I am able to INSERT INTO tables, as I have done it before. Where I have been having issues is to BULK INSERT. I am using BULK…
Grant Herman
  • 923
  • 2
  • 13
  • 29
16
votes
4 answers

"No driver name specified" writing pandas data frame into SQL Server table

I am trying to write a Pandas' DataFrame into an SQL Server table. Here is my example: import pyodbc import pandas as pd import sqlalchemy df = pd.DataFrame({'MDN': [242342342] }) engine =…
user1700890
  • 7,144
  • 18
  • 87
  • 183
16
votes
1 answer

SQL Update statement but using pyodbc

I am using a pyodbc driver to connect to a microsoft access table using SQL. Does anyone know how I go about replacing fields within this table?? I have though about deleting the row and then putting the row back but that would change the primary…
MrPython
  • 239
  • 1
  • 3
  • 12
16
votes
7 answers

"General error Unable to open registry key Temporary (volatile) ..." from Access ODBC

I tried the following: private String password = ""; private String dbName = "dataHC.accdb"; private String bd = dbName + ";PWD=" + password; String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ="+bd+";"; private…
Erika Hernández
  • 357
  • 2
  • 3
  • 9
16
votes
5 answers

make python wait for stored procedure to finish executing

I have a python script that uses pyodbc to call an MSSQL stored procedure, like so: cursor.execute("exec MyProcedure @param1 = '" + myparam + "'") I call this stored procedure inside a loop, and I notice that sometimes, the procedure gets called…
Ben Caine
  • 1,128
  • 3
  • 15
  • 25
16
votes
7 answers

SQL Server, Python, and OS X

What's a good way to interface Python running on OS X with a cloud-based SQL Server database? EDIT: With pyodbc I'm getting this error: >>> import pyodbc >>> cnxn = pyodbc.connect('DRIVER={SQL…
Ben Hamner
  • 4,575
  • 4
  • 30
  • 50
15
votes
4 answers

pip install pyodbc failed ERROR: Failed building wheel for pyodbc

I'am trying to import pyodbc library into google colab, but i'am getting this error. Just in case, I have Anaconda installed in my notebook, and I never had problem with pyodbc in there. Can you help me please? Tks! Collecting pyodbc Using cached…
Phelipe
  • 179
  • 1
  • 1
  • 11
15
votes
3 answers

"Login timeout expired" error when accessing MS SQL db via sqlalchemy and pyodbc

So I have some trouble getting sqlalchemy and pyodbc working with a remote MS SQL Server. Local sqlcmd worked properly but not when I try to read the db via python code. Any help would be appreciated. Environment: Centos 7 SQLCmd version: Version…
ttback
  • 2,051
  • 5
  • 27
  • 40
15
votes
4 answers

SQL IN operator using pyodbc and SQL Server

I'm using pyodbc to query to an SQL Server database import datetime import pyodbc conn = pyodbc.connect("Driver={SQL Server};Server='dbserver',Database='db', TrustedConnection=Yes") cursor = conn.cursor() ratings =…
user338714
  • 2,315
  • 5
  • 27
  • 36
15
votes
1 answer

Building a connection URL for mssql+pyodbc with sqlalchemy.engine.url.URL

The problem... I am trying to connect to a MSSql server via SQLAlchemy. Here is my code with fake credentials (not my real credentials obviously). The code... credentials = { 'username' : 'SPOTTER_xyz_ACC', 'password' :…
Clay
  • 577
  • 3
  • 8
  • 14