pyodbc

Read data from pyodbc to pandas

蓝咒 提交于 2019-11-27 00:53:56
问题 I am querying a SQL database and I want to use pandas to process the data. However, I am not sure how to move the data. Below is my input and output. import pyodbc import pandas from pandas import DataFrame cnxn = pyodbc.connect(r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\users\bartogre\desktop\CorpRentalPivot1.accdb;UID="";PWD="";') crsr = cnxn.cursor() for table_name in crsr.tables(tableType='TABLE'): print(table_name) cursor = cnxn.cursor() sql = "Select sum(CYTM), sum(PYTM)

SqlAlchemy equivalent of pyodbc connect string using FreeTDS

孤人 提交于 2019-11-27 00:29:31
问题 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 sqlalchemy sqlalchemy.create_engine("mssql://myuser:mypwd@my.db.server:1433/mydb?driver=FreeTDS& odbc_options='TDS_Version=8.0'").connect() The error message for above is: DBAPIError: (Error) ('08001', '[08001] [unixODBC][FreeTDS][SQL Server]Unable to connect to data source (0) (SQLDriverConnectW)') None None Can

How to see the real SQL query in Python cursor.execute using pyodbc and MS-Access

ぃ、小莉子 提交于 2019-11-27 00:20:48
问题 I use the following code in Python (with pyodbc for a MS-Access base). cursor.execute("select a from tbl where b=? and c=?", (x, y)) It's Ok but, for maintenance purposes, I need to know the complete and exact SQL string send to the database. Is it possible and how ? 回答1: It differs by driver. Here are two examples: import MySQLdb mc = MySQLdb.connect() r = mc.cursor() r.execute('select %s, %s', ("foo", 2)) r._executed "select 'foo', 2" import psycopg2 pc = psycopg2.connect() r = pc.cursor()

python pip specify a library directory and an include directory

删除回忆录丶 提交于 2019-11-27 00:02:16
I am using pip and trying to install a python module called pyodbc which has some dependencies on non-python libraries like unixodbc-dev, unixodbc-bin, unixodbc. I cannot install these dependencies system wide at the moment, as I am only playing, so I have installed them in a non-standard location. How do I tell pip where to look for these dependencies ? More exactly, how do I pass information through pip of include dirs (gcc -I) and library dirs (gcc -L -l) to be used when building the pyodbc extension ? pip has a --global-option flag You can use it to pass additional flags to build_ext . For

pyodbc on Azure

那年仲夏 提交于 2019-11-26 23:32:47
问题 I have a python webapp in Azure which I would like to read from an SQLServer also in Azure in the same resource group. Following this example Connecting to Microsoft SQL server using Python, I have added pyodbc to my requirements.txt, the deployment to Azure fails complaining that it doesn't have the correct version of C++ redistributable (9.0) available. Is there anything that can be done about this, or is a different architecture required (and if so, which?)? 回答1: I tried to access Azure

using pyodbc on linux to insert unicode or utf-8 chars in a nvarchar mssql field

♀尐吖头ヾ 提交于 2019-11-26 22:48:18
问题 I am using Ubuntu 9.04 I have installed the following package versions: unixodbc and unixodbc-dev: 2.2.11-16build3 tdsodbc: 0.82-4 libsybdb5: 0.82-4 freetds-common and freetds-dev: 0.82-4 I have configured /etc/unixodbc.ini like this: [FreeTDS] Description = TDS driver (Sybase/MS SQL) Driver = /usr/lib/odbc/libtdsodbc.so Setup = /usr/lib/odbc/libtdsS.so CPTimeout = CPReuse = UsageCount = 2 I have configured /etc/freetds/freetds.conf like this: [global] tds version = 8.0 client charset = UTF-8

PYODBC--Data source name not found and no default driver specified

送分小仙女□ 提交于 2019-11-26 20:43:20
问题 import pyodbc connection = pyodbc.connect('Driver = {SQL Server};Server=SIWSQL43A\SIMSSPROD43A;' 'Database=CSM_reporting;Trusted_Connection=yes;') connection = pyodbc.connect('Driver = {SQL Server};Server=SIWSQL43A\SIMSSPROD43A;' pyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)') 回答1: Do not put a space after the Driver keyword in the connection string. This fails on Windows ... conn_str = ( r

Connect docker python to SQL server with pyodbc

不想你离开。 提交于 2019-11-26 20:15:02
问题 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), Does anyone have a working dockerfile, using pyodbc: Dockerfile: # Use an official Python runtime as a parent image FROM python:2.7-slim # Set the working directory to /app WORKDIR /app # Copy the current directory contents into the container at

SQL Server, Python, and OS X

大城市里の小女人 提交于 2019-11-26 19:19:43
问题 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 Server};SERVER=adsf.com;DATABASE=asdf;UID=asdf;PWD=asdf') Traceback (most recent call last): File "<stdin>", line 1, in <module> pyodbc.Error: ('00000', '[00000] [iODBC][Driver Manager]dlopen({SQL Server}, 6): image not found (0) (SQLDriverConnect)') 回答1: SQLAlchemy is probably your best bet. It has an

Get data from pandas into a SQL server with PYODBC

≡放荡痞女 提交于 2019-11-26 17:43:50
问题 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 from the FTP server first which works fine.... If I then remove this code and change it to a select from ms sql server it is fine so the connection string works, but the insertion into the SQL server seems to be causing problems. import pyodbc import