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
1
vote
1 answer

Parse SQL parameter marker with pandas using dynamic tables

I have the following code: query = """ DECLARE @DATABASE VARCHAR(128) = '{}'; DECLARE @SCHEMA VARCHAR(128) = '{}'; DECLARE @TABLE VARCHAR(128) = '{}'; DECLARE @sql VARCHAR(200) = 'SELECT * FROM ' + CONCAT(QUOTENAME(@DATABASE),…
Alejandro Alcalde
  • 5,990
  • 6
  • 39
  • 79
1
vote
2 answers

How do I get pyodbc to Work in Azure Web App

Getting the following error - when trying to view a Flask web app that is deployed to Azure using pyodbc: 2019-09-03T14:25:35.575624728Z conn = pyodbc.connect('Driver={SQL Server};' 2019-09-03T14:25:35.575857932Z pyodbc.Error: ('01000', "[01000]…
1
vote
0 answers

PYODBC Cannot find driver for MSSQL

I am attempting to connect to SQL Server using a simple python script that looks like the following. import pyodbc details = { 'server': '', 'database': '', 'username': '', 'password':…
bipvanwinkle
  • 104
  • 1
  • 1
  • 6
1
vote
1 answer

Is there a way in Django to always CAST a specific Field to VARCHAR?

Background Situation Description: I'm creating a Django2 application which use a Microsoft SQL Server as back-end database. This database has several tables (which I cannot manage or change them) containing SQL_VARIANT fields. This fields contains…
1
vote
1 answer

Running simple query through python: No results

I am trying to learn how to get Microsoft SQL query results using python and pyodbc module and have run into an issue in returning the same results using the same query that I use in Microsoft SQL Management Studio. I've looked at the pyodbc…
iNeedScissors61
  • 191
  • 1
  • 4
  • 16
1
vote
1 answer

Construct a big json response from multiple pyodbc database query result

I'm constructing json response from data in database using pyodbc. Some of the fields are direct mapping from table column, whereas some of them have to be in list, dict format. Table structure and data looks like below custid | custacct |…
more09
  • 57
  • 1
  • 7
1
vote
1 answer

Updating Oracle DB via pyodbc hangs

I'm having issues with pyodbc used with an Oracle DB. I can do select statements with results coming back, however when I try to update a record, the program seems to hang during the "conn.execute(query)" line with no error messages. I have to force…
Ray Chan
  • 35
  • 5
1
vote
2 answers

Connect to Oracle with ODBC in Python

I managed to install Oracle 12.2.01, running its official Docker image on 64bit Linux with: docker run --name oracle12-se2 -p 1521:1521 -p 5500:5500 -e ORACLE_PWD=my_pwd oracle/database:12.2.0.1-se2 The database seems to be running correctly, I can…
user124114
  • 8,372
  • 11
  • 41
  • 63
1
vote
0 answers

Azure DevOps build Agent: No Kerberos credentials available

I have a custom Linux build agent in my Azure DevOps project. One of the builds uploads a SQL database to Azure SQL Databases through a Python script using sqlalchemyand ODBC Driver 17 for SQL Server. Recently the build fails with the following…
1
vote
0 answers

Need to pass a string with single \ character in python

I have looked at various solutions and am familiar with using the \ as an escape character. Im in a situation where I need to pass credentials over pyodbc and in making my connection string I need to pass credentials, unfortunately my username is in…
mitch
  • 379
  • 1
  • 3
  • 14
1
vote
0 answers

How to use pyodbc on a .accdb file linked to a sharepoint list

I'm having issues with the following lines of code: print("Before") conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=C:\\Users\\userName\\Desktop\\Project Folders\\sharepointList\\test.accdb;') print("After") I…
1
vote
1 answer

Dataframe writing datatypes into txt file

I have a column(date field) in the txt file(textfile_A) and i am reading max date in that column and passing that max_date value into my sql query , finally i am trying to export my results into txt(textfile_B) like in below format ,i have tried the…
Rahul
  • 467
  • 1
  • 8
  • 24
1
vote
0 answers

Pyodbc extract result set from stored procedure

I have MSSQL stored procedure that takes 1 input parameter. When I execute it in SQL client it returns a set of rows and columns: +-------------+----------+ | text| dt| +-------------+----------+ |Sample Text 1|2019-01-01| |Sample…
Byrdziu
  • 107
  • 1
  • 9
1
vote
1 answer

Creating new column for unique code for each row on column basis using python

I was trying to create a query loop, which does interactive steps from one instance to the next. After fetching the right data. Connected python to SQL server and returned table schema column name and type in a variable. Here I am trying to create…
user11877626
1
vote
0 answers

Is there a solution for connecting to a Microsoft Access database with Python?

I can't connect to a Microsoft Access database using pyodbc as below: import pyodbc conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Users\zghid\Desktop\Database1.accdb;') cursor =…
someone
  • 53
  • 1
  • 8