pyodbc

How to execute query saved in MS Access using pyodbc

☆樱花仙子☆ 提交于 2019-11-28 01:40:22
There are a lot of tips online on how to use pyodbc to run a query in MS Access 2007, but all those queries are coded in the Python script itself. I would like to use pyodbc to call the queries already saved in MS Access. How can I do that? If the saved query in Access is a simple SELECT query with no parameters then the Access ODBC driver exposes it as a View so all you need to do is use the query name just like it was a table: import pyodbc connStr = ( r"Driver={Microsoft Access Driver (*.mdb, *.accdb)};" r"DBQ=C:\Users\Public\Database1.accdb;" ) cnxn = pyodbc.connect(connStr) sql = """\

pyodbc on Azure

给你一囗甜甜゛ 提交于 2019-11-28 01:35:59
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?)? I tried to access Azure SQL Database in my flask web app. You could refer to my working code. view.py from datetime import datetime

Reading DBF files with pyodbc

只谈情不闲聊 提交于 2019-11-28 01:35:01
问题 In a project, I need to extract data from a Visual FoxPro database, which is stored in dbf files, y have a data directory with 539 files I need to take into account, each file represents a database table, so I've been doing some testing and my code goes like this: import pyodbc connection = pyodbc.connect("Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=P:\\Data;Exclusive=No;Collate=Machine;NULL=No;DELETED=Yes") tables = connection.cursor().tables() for _ in tables: print _

How to install pyodbc 64-bit?

南楼画角 提交于 2019-11-28 00:53:45
问题 I have Python 2.7, MySQL 5.5, MySQL ODBC Connector 5.1, and pyodbc all installed on my computer, which is running Windows 7, 64-bit... Only problem is that everything is installed as 64-bit except pyodbc, which is 32-bit. When using easy_install to download pyodbc, it automatically downloads the 32-bit version. Thus, when I try to connect to my database using: cnxn = pyodbc.connect('DRIVER={MySQL ODBC 5.1 DRIVER};SERVER=localhost;DATABASE=test;UID=root;PWD=password') I get the error: Data

MSSQL2008 - Pyodbc - Previous SQL was not a query

柔情痞子 提交于 2019-11-27 20:06:35
I can't figure out what's wrong with the following code, The syntax IS ok (checked with SQL Management Studio), i have access as i should so that works too.. but for some reason as soon as i try to create a table via PyODBC then it stops working. import pyodbc def SQL(QUERY, target = '...', DB = '...'): cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=' + target + DB+';UID=user;PWD=pass') cursor = cnxn.cursor() cursor.execute(QUERY) cpn = [] for row in cursor: cpn.append(row) return cpn print SQL("CREATE TABLE dbo.Approvals (ID SMALLINT NOT NULL IDENTITY PRIMARY KEY, HostName char(120));") It

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

时间秒杀一切 提交于 2019-11-27 19:24:56
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 I have grabbed pyodbc revision 31e2fae4adbf1b2af1726e5668a3414cf46b454f from http://github.com

Python - pyodbc call stored procedure with parameter name

徘徊边缘 提交于 2019-11-27 18:44:27
问题 I need to call a SqlServer stored procedure from python2.7 via pyodbc module with input parameter name. I tried based on documentation by input parameter order: cursor.execute('{CALL [SP_NAME](?,?)}', ('value', 'value')) It works, but I need to pass parameter name of stored procedure because order of stored procedure input parameter always changes. So I need to pass them by name. cursor.execute('{CALL [SP_NAME](@param1name,@param2name)}', ('value', 'value')) However this doesn't work. What's

Can't open lib 'ODBC Driver 13 for SQL Server'? Sym linking issue?

北战南征 提交于 2019-11-27 18:09:43
When I try to connect to a sql server database with pyodbc (on mac): import pyodbc server = '####' database = '####' username = '####@####' password = '#####' driver='{ODBC Driver 13 for SQL Server}' pyodbc.connect('DRIVER='+driver+';SERVER='+server+';PORT=1443;DATABASE='+database+';UID='+username+';PWD='+password) I get the following error: Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 13 for SQL Server' : file not found (0) (SQLDriverConnect)") When I path in the actual driver location: driver='/usr/local/lib/libmsodbcsql.13.dylib' It starts working! My

Writing a csv file into SQL Server database using python

我们两清 提交于 2019-11-27 18:03:12
Hi I am trying to write a csv file into a table in SQL Server database using python. I am facing errors when I pass the parameters , but I don't face any error when I do it manually. Here is the code I am executing. cur=cnxn.cursor() # Get the cursor csv_data = csv.reader(file(Samplefile.csv')) # Read the csv for rows in csv_data: # Iterate through csv cur.execute("INSERT INTO MyTable(Col1,Col2,Col3,Col4) VALUES (?,?,?,?)",rows) cnxn.commit() Error :pyodbc.DataError: ('22001', '[22001] [Microsoft][ODBC SQL Server Driver][SQL Server]String or binary data would be truncated. (8152)

SQL Server, Python, and OS X

放肆的年华 提交于 2019-11-27 18:02:55
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)') SQLAlchemy is probably your best bet. It has an ORM, but doesn't require its use. MS SQL is supported through a number of DBAPI projects. As for lower-level