pyodbc

“Optional feature not implemented (106) (SQLBindParameter)” error with pyodbc

旧时模样 提交于 2019-11-29 11:41:41
I'm being driven nuts trying to figure this one out. I'm using Python for the first time, and trying to write data collected from twitter out to an Access 2010 database. The command I'm using is: cursor.execute('''insert into core_data(screen_name,retweet_count) values (?,?,)''', (sname,int(rcount))) The error message being returned is: Traceback (most recent call last): File "C:/Documents and Settings/Administrator/PycharmProjects/clientgauge/tw_scraper.py", line 44, in <module> cursor.execute('''insert into core_data(screen_name,retweet_count) values (?,?,)''', (sname,int(rcount))) pyodbc

Cannot perform a backup or restore operation within a transaction

℡╲_俬逩灬. 提交于 2019-11-29 11:12:56
I am using PyODBC to back up my database, using following code: SQL_command = """ BACKUP DATABASE [MyDatabase] TO DISK = N'D:\MSSQL\BACKUP\MyDatabase_20141212.bak' WITH NOFORMAT , NOINIT , NAME = N'MyDatabase_20141212' , SKIP , REWIND , NOUNLOAD , STATS = 10 """ conn.cursor.execute(SQL_command) conn.cursor.commit() The above code give me an error message: pyodbc.ProgrammingError: ('42000', '[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot perform a backup or restore operation within a transaction. (3021) (SQLExecDirectW); [42000] [Microsoft][ODBC SQL Server Driver][SQL Server

In Python, Using pyodbc, How Do You Perform Transactions?

限于喜欢 提交于 2019-11-29 10:48:50
I have a username which I must change in numerous (up to ~25) tables. (Yeah, I know.) An atomic transaction seems to be the way to go for this sort of thing. However, I do not know how to do this with pyodbc. I've seen various tutorials on atomic transactions before, but have never used them. The setup: Windows platform, Python 2.6, pyodbc, Microsoft SQL 2005. I've used pyodbc for single SQL statements, but no compound statements or transactions. Best practices for SQL seem to suggest that creating a stored procedure is excellent for this. My fears about doing a stored procedure are as follows

Access second result set of stored procedure with SQL or other work-around? Python\\pyodbc

南笙酒味 提交于 2019-11-29 09:58:05
I'm using python\pyodbc and would like to access the second result set of a stored procedure. As near as I can tell, pyodbc does not support multiple result sets. Additionally, I can't modify the stored procedure. Are there any options to access the second result set using SQL or some other work-around? Perhaps create a second stored procedure that only returns the second result set of the first? No need for anything fancy. Just use nextset: import pyodbc db = pyodbc.connect ("") q = db.cursor () q.execute (""" SELECT TOP 5 * FROM INFORMATION_SCHEMA.TABLES SELECT TOP 10 * FROM INFORMATION

Reading DBF files with pyodbc

流过昼夜 提交于 2019-11-29 07:23:33
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 _ this prints only 15 tables, with no obvious pattern, always the same 15 tables, I thought this was

How to install pyodbc 64-bit?

自闭症网瘾萝莉.ら 提交于 2019-11-29 07:13:19
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 source name not found and no default driver specified (0) (SQLDriverConnect) And when I try to specify a

Python multiprocessing and database access with pyodbc “is not safe”?

柔情痞子 提交于 2019-11-29 06:32:04
The Problem: I am getting the following traceback and don't understand what it means or how to fix it: Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Python26\lib\multiprocessing\forking.py", line 342, in main self = load(from_parent) File "C:\Python26\lib\pickle.py", line 1370, in load return Unpickler(file).load() File "C:\Python26\lib\pickle.py", line 858, in load dispatch[key](self) File "C:\Python26\lib\pickle.py", line 1083, in load_newobj obj = cls.__new__(cls, *args) TypeError: object.__new__(pyodbc.Cursor) is not safe, use pyodbc.Cursor.__new__() The

pyodbc - very slow bulk insert speed

我怕爱的太早我们不能终老 提交于 2019-11-29 05:53:46
问题 With this table: CREATE TABLE test_insert ( col1 INT, col2 VARCHAR(10), col3 DATE ) the following code takes 40 seconds to run: import pyodbc from datetime import date conn = pyodbc.connect('DRIVER={SQL Server Native Client 10.0};' 'SERVER=localhost;DATABASE=test;UID=xxx;PWD=yyy') rows = [] row = [1, 'abc', date.today()] for i in range(10000): rows.append(row) cursor = conn.cursor() cursor.executemany('INSERT INTO test_insert VALUES (?, ?, ?)', rows) conn.commit() The equivalent code with

Can I use multiple cursors on one connection with pyodbc and MS SQL Server?

泪湿孤枕 提交于 2019-11-29 05:52:00
I'm using pyodbc on python 2.6 to connect to Microsoft SQL Server 2005. I open a connection, create a couple of cursors: c1 = connection.cursor() c2 = connection.cursor() and then run a query on the first cursor. c1.execute("select * from foo") Now I run a query on the second cursor: c2.execute("select * from bar") ...and I get an error: "Connection is busy with results for another hstmt." After I do a c1.fetchall() or c1.close() then I can use c2. My question is: Why am I even allowed to create multiple cursors on a connection, if I'm only allowed to use one at a time, and the same one can

Python - pyodbc call stored procedure with parameter name

ε祈祈猫儿з 提交于 2019-11-29 04:47:28
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 the correct syntax? I tested this using the following stored procedure in SQL Server 2008 R2: CREATE