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

CREATE PROCEDURE fails silently when called from pyodbc

I am unable to create a SQL Server stored procedure using Python's pyodbc. The command executes correctly and I get no error message however the stored procedure does not appear on the server import pyodbc host = 'myServer' database = 'model' conn…
michal111
  • 400
  • 4
  • 18
1
vote
0 answers

Getting error from Pandas DataFrame.to_sql while loading a file to Informix Database

I am getting an error while loading a file using Pandas Dataframe's to_sql method on an Informix Database. I am able to connect to the Informix database and execute the select query using the read_sql_query method like so: df =…
Rajesh
  • 65
  • 6
1
vote
1 answer

Mixing strings and input variable in sql connection string using pyodbc library - Python

I've had a look around SO and couldn't find this particular issue. So I have an ext config.txt file which is used to obtain values which are stored in variables in the python program. I have a variable in the python that stores the key:values in…
1
vote
1 answer

SQL Query not always inserting missing values

I am writing a SQL query to update a table from another table. My goal is for my query to insert records from table2 into table1 if that record is not found in table1. The query works great when table1 is completely empty, but when I delete a couple…
Gpsy
  • 100
  • 11
1
vote
0 answers

How to resolve SQL bind error when using an pyodbc UPDATE command to update an sql table?

My initial problem occured when I was when I attempted to use pyodbc to update values in a table using a sql UPDATE statement. The error is occuring because the variable MonthNum that I am using is an integer value. The error that occurs…
1
vote
0 answers

Writing a csv file into SQL Table using python

Hi I am trying to write a csv file into a table in SQL Server database using python. I am facing errors. Here is the code I am executing. CSV file contains more than 500 rows def LoadFile(self, hierarchySetId, fileName): try: …
Paras
  • 63
  • 1
  • 6
1
vote
0 answers

Error connecting to MarkLogic ODBC server from pyodbc on Windows

I am trying to connect to MarkLogic ODBC server using pyodbc. The connection opens fine. However, when I run a query with cursor.execute, I get an error, XDMP-UNEXPECTED: (err:XPST0003) Unexpected token syntax error, unexpected "", expecting "" As…
Yogesh Sajanikar
  • 1,086
  • 7
  • 19
1
vote
2 answers

Better way to do bulk update in mssql using pyodbc?

I want to do bulk update from my python code to mssql DB. Im using pyodbc 4.0.26 version. What is the best way to do update in bulk? My cursor object lists only 'execute' method. I don't see any other methods. I want to scan db for few hundreds…
Ratha
  • 9,434
  • 17
  • 85
  • 163
1
vote
0 answers

Python Export Blob From SQL Server

I have a table in SQL Server with a varbinary(max) column that contains file blobs. I am exporting these with Python and pyodbc like this: import pyodbc conn = pyodbc.connect('DSN=SQL Server;UID=username;PWD=password') cursor = conn.cursor() with…
OverflowingTheGlass
  • 2,324
  • 1
  • 27
  • 75
1
vote
1 answer

SQL query results reporting date column as a string, having issues getting it in a date datatype

I'm querying some data from SQL Server into Python using pyodbc and storing the results in a pandas dataframe. One of the resulting columns should be a date datatype but it is coming over as a object. I am trying to figure out how I can work with…
Emily Reed
  • 65
  • 10
1
vote
0 answers

Pycharm does not recognize pyodbc

I want to acces an mysql server via a python script. Unfortunately it seems like pip does not install the pyodbc module correctly, because I get the "Module not found"-Error, when trying to import pydbc. But the module is listed as installed in the…
1
vote
1 answer

Able to access data through pyodbc and SELECT statements, but no new tables show up in SQL

I have the following code which is working with no errors and returning the expected output when I print the results of the pyodbc cursor I created. cnxn = pyodbc.connect(MY_URL) cursor = cnxn.cursor() cursor.execute( ''' CREATE TABLE…
user11643374
1
vote
2 answers

Errors on connection to MSSQL using turbodbc

I cannot connect using values read from a config file. This is on Windows, connecting to SQL Server 2008r2 on the same machine, using Python 3.6. This works: conn = p.connect(driver = '{SQL Server Native Client 11.0}', server = 'SERVERNAME',port =…
tfillmor
  • 11
  • 2
1
vote
0 answers

pyodbc InterfaceError: sqlalchemy.create_engine(mssql+pyodbc://...)

The create_engine() statement doesn't seem to work when using mssql+pyodbc, it throws an InterfaceError. The same happens when I try to use turbodbc. However, it works fine when using mssql+pymssql. Mainly, I'm trying to speed up my df.to_sql()…
corr
  • 73
  • 1
  • 7
1
vote
1 answer

How to use pyodbc, cursor, execute to extract data from SQL when there is no parameters for query.format?

Usually, I use the following way to extract data from SQL using Python: myConnect=pyodbc.connect('DSN=B1P HANA;UID=****;PWD=****') myCursor=myConnect.cursor() Start1=20150101 End=20200101 query = """ SELECT "Operator", …
Feng Chen
  • 2,139
  • 4
  • 33
  • 62