pyodbc

pyodbc the sql contains 0 parameter markers but 1 parameters were supplied' 'hy000'

元气小坏坏 提交于 2019-11-29 02:26:50
I am using Python 3.6, pyodbc, and connect to SQL Server. I am trying make connection to a database, then creating a query with parameters. Here is the code: import sys import pyodbc # connection parameters nHost = 'host' nBase = 'base' nUser = 'user' nPasw = 'pass' # make connection start def sqlconnect(nHost,nBase,nUser,nPasw): try: return pyodbc.connect('DRIVER={SQL Server};SERVER='+nHost+';DATABASE='+nBase+';UID='+nUser+';PWD='+nPasw) print("connection successfull") except: print ("connection failed check authorization parameters") con = sqlconnect(nHost,nBase,nUser,nPasw) cursor = con

Connecting to MS Access 2007 (.accdb) database using pyodbc

醉酒当歌 提交于 2019-11-29 02:05:38
I am on Win7 x64, using Python 2.7.1 x64. I am porting an application I created in VC++ to Python for educational purpouses. The original application has no problem connecting to the MS Access 2007 format DB file by using the following connection string: OleDbConnection^ conn = gcnew OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=|DataDirectory|DB.accdb"); Now, when I try to connect to the same DB file (put in C:\ this time) in Python using pyodbc and the following conenction string: conn = pyodbc.connect("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; Provider=Microsoft

Common ways to connect to odbc from python on windows? [closed]

回眸只為那壹抹淺笑 提交于 2019-11-28 22:29:37
问题 What library should I use to connect to odbc from python on windows? Is there a good alternative for pywin32 when it comes to odbc? I'm looking for something well-documented, robust, actively maintained, etc. pyodbc looks good -- are there any others? 回答1: You already suggested pyodbc , and I am going to agree with you. It has given me the least amount of issues in my experience; I've used pymssql and adodbapi, and when those threw exceptions/created issues, I swapped out the code and

Cant Create tables in access with pyodbc

走远了吗. 提交于 2019-11-28 21:25:03
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? You need to commit the transaction: import pyodbc con = pyodbc.connect(r'DRIVER={Microsoft Access Driver (*.mdb, *

Connecting to SQL Server 2012 using sqlalchemy and pyodbc

北慕城南 提交于 2019-11-28 20:19:38
问题 I'm trying to connect to a SQL Server 2012 database using SQLAlchemy (with pyodbc) on Python 3.3 (Windows 7-64-bit). I am able to connect using straight pyodbc but have been unsuccessful at connecting using SQLAlchemy. I have dsn file setup for the database access. I successfully connect using straight pyodbc like this: con = pyodbc.connect('FILEDSN=c:\\users\\me\\mydbserver.dsn') For sqlalchemy I have tried: import sqlalchemy as sa engine = sa.create_engine('mssql+pyodbc://c/users/me

Read data from pyodbc to pandas

时光毁灭记忆、已成空白 提交于 2019-11-28 19:13:59
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), BRAND From data Group By BRAND" cursor.execute(sql) for data in cursor.fetchall(): print (data) ('C:\

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

你说的曾经没有我的故事 提交于 2019-11-28 19:00:29
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 charset = UTF-8 text size = 4294967295 I have grabbed pyodbc revision

Unable to install pyodbc on Linux

我们两清 提交于 2019-11-28 16:56:45
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-record.txt failed with error code 1 Has anybody had a similar issue installing pyodbc? Jim Clouse On

Using Sql Server with Django in production

纵饮孤独 提交于 2019-11-28 16:20:24
Has anybody got recent experience with deploying a Django application with an SQL Server database back end? Our workplace is heavily invested in SQL Server and will not support Django if there isn't a sufficiently developed back end for it. I'm aware of mssql.django-pyodbc and django-mssql as unofficially supported back ends. Both projects seem to have only one person contributing which is a bit of a worry though the contributions seem to be somewhat regular. Are there any other back ends for SQL Server that are well supported? Are the two I mentioned here 'good enough' for production? What

Can't insert Date and Time to sql server via pyodbc

雨燕双飞 提交于 2019-11-28 14:47:39
I'm trying to insert date and time to SQL server in Linux (raspbian) environment using python language.So far i was able connect to MS Sql and also i created a table and im using pyodbc. #! /user/bin/env python import pyodbc import datetime dsn = 'nicedcn' user = myid password = mypass database = myDB con_string = 'DSN=%s;UID=%s;PWD=%s;DATABASE=%s;' % (dsn, user, password, database) cnxn = pyodbc.connect(con_string) cursor = cnxn.cursor() string = "CREATE TABLE Database3([row name] varchar(20), [my date] date), [my time] time)" cursor.execute(string) cnxn.commit() This part complied without