pyodbc

to_sql pyodbc count field incorrect or syntax error

萝らか妹 提交于 2019-11-27 14:14:01
I am downloading Json data from an api website and using sqlalchemy, pyodbc and pandas' to_sql function to insert that data into a MSSQL server. I can download up to 10000 rows, however I have to limit the chunksize to 10 otherwise I get the following error: DBAPIError: (pyodbc.Error) ('07002', '[07002] [Microsoft][SQL Server Native Client 11.0]COUNT field incorrect or syntax error (0) (SQLExecDirectW)') [SQL: 'INSERT INTO [TEMP_producing_entity_details] There are around 500 Million rows to download, it's just crawling at this speed. Any advice on a workaround? Thanks, UPDATE: pandas 0.23.1

Cant Create tables in access with pyodbc

北慕城南 提交于 2019-11-27 13:58:19
问题 I am trying to create tables in a MS Access DB with python using pyodbc but when I run my script no tables are created and no errors are given. My code: #!/usr/bin/env python import pyodbc con = pyodbc.connect(r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=Z:\Data\Instruments\testDB.accdb; Provider=MSDASQL;') cur = con.cursor() string = "CREATE TABLE TestTable(symbol varchar(15), leverage double, shares integer, price double)" cur.execute(string) What could be wrong? 回答1: You need to

Get data from pandas into a SQL server with PYODBC

偶尔善良 提交于 2019-11-27 13:14:19
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 pandas from ftplib import FTP from StringIO import StringIO import csv ftp = FTP ('ftp.xyz.com','user',

python pandas to_sql with sqlalchemy : how to speed up exporting to MS SQL?

跟風遠走 提交于 2019-11-27 12:56:19
问题 I have a dataframe with ca 155,000 rows and 12 columns. If I export it to csv with dataframe.to_csv , the output is an 11MB file (which is produced instantly). If, however, I export to a Microsoft SQL Server with the to_sql method, it takes between 5 and 6 minutes! No columns are text: only int, float, bool and dates. I have seen cases where ODBC drivers set nvarchar(max) and this slows down the data transfer, but it cannot be the case here. Any suggestions on how to speed up the export

using pyodbc on ubuntu to insert a image field on SQL Server

◇◆丶佛笑我妖孽 提交于 2019-11-27 11:48:49
问题 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 python2.6-dev 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

Connecting to MS SQL Server with Windows Authentication using Python?

十年热恋 提交于 2019-11-27 11:39:56
How do I connect MS SQL Server using Windows Authentication, with the pyodbc library? I can connect via MS Access and SQL Server Management Studio, but cannot get a working connection ODBC string for Python. Here's what I've tried (also without 'Trusted_Connection=yes' ): pyodbc.connect('Trusted_Connection=yes', driver='{SQL Server}', server='[system_name]', database='[databasename]') pyodbc.connect('Trusted_Connection=yes', uid='me', driver='{SQL Server}', server='localhost', database='[databasename]') pyodbc.connect('Trusted_Connection=yes', driver='{SQL Server}', server='localhost', uid='me

Output pyodbc cursor results as python dictionary

人走茶凉 提交于 2019-11-27 10:51:37
How do I serialize pyodbc cursor output (from .fetchone , .fetchmany or .fetchall ) as a Python dictionary? I'm using bottlepy and need to return dict so it can return it as JSON. Bryan If you don't know columns ahead of time, use cursor.description to build a list of column names and zip with each row to produce a list of dictionaries. Example assumes connection and query are built: >>> cursor = connection.cursor().execute(sql) >>> columns = [column[0] for column in cursor.description] >>> print(columns) ['name', 'create_date'] >>> results = [] >>> for row in cursor.fetchall(): ... results

Unable to install pyodbc on Linux

送分小仙女□ 提交于 2019-11-27 09:56:21
问题 I am running Linux (2.6.18-164.15.1.el5.centos.plus) and trying to install pyodbc. I am doing pip install pyodbc and get a very long list of errors, which end in error: command 'gcc' failed with exit status 1 I looked in /root/.pip/pip.log and saw the following: InstallationError: Command /usr/local/bin/python -c "import setuptools; file ='/home/build/pyodbc/setup.py'; execfile('/home/build/pyodbc/setup.py')" install --single-version-externally-managed --record /tmp/pip-7MS9Vu-record/install

How to connect pyodbc to an Access (.mdb) Database file

為{幸葍}努か 提交于 2019-11-27 09:32:30
Here's what I've tried: -Find Vista's ODBC Data Source Manager* through search, -Add a new File Data Source*, selecting Driver for Microsoft Access (*.mdb), and selecting my mdb file of interest, -import pyodbc from python shell and try: pyodbc.connect("DSN=<that Data Source I just created>") I get the following error message (Portuguese**): Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Nome da fonte de dados n\xe3o encontrado e nenhum driver padr\xe3o especificado (0) (SQLDriverConnectW)') Which translates as "Data source name not found and no standard driver specified". What am

pyodbc requires python 3.3

风流意气都作罢 提交于 2019-11-27 08:48:02
问题 I just downloaded installer for pyodbc from google project. I have Python 3.5 istalled and pyodbc requires 3.3. Is there an easy work around? P.S. I am installing it on PC without Internet access. This is for Windows. 回答1: Since you can't install this via the regular pip channels, you can download a prebuilt binary for Python 3.5 from Chris Gohlke's site, where he has a bunch of libraries he creates builds for. Download either depending on the version of Python 3.5 you have installed: pyodbc