pyodbc

Why would I get a memory error with fast_executemany on a tiny df?

泪湿孤枕 提交于 2019-12-05 00:26:17
问题 I was looking for ways to speed up pushing a dataframe to sql server and stumbled upon an approach here. This approach blew me away in terms of speed. Using normal to_sql took almost 2 hours and this script was done in 12.54 seconds to push a 100k row X 100 column df. So after testing the code below with a sample df, I attempted to use a df that had many different datatypes (int, string, floats, Booleans). However, I was sad to see a memory error. So I started reducing the size of my df to to

INSERT INTO Access database from pandas DataFrame

房东的猫 提交于 2019-12-04 20:59:51
Please could somebody tell me how should look like insert into the database but of the all data frame in python? I found this but don't know how to insert all data frame called test_data with two figures: ID, Employee_id. I also don't know how to insert the next value for ID (something like nextval) Thank you import pyodbc conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\Users\test_database.mdb;') cursor = conn.cursor() cursor.execute(''' INSERT INTO employee_table (ID, employee_id) VALUES(?????????) ''') conn.commit() Gord Thompson You can use pyodbc's executemany

pyODBC and SQL Server 2008 and Python 3

非 Y 不嫁゛ 提交于 2019-12-04 20:23:01
I have pyODBC installed for Python 3.2 and I am attempting to update a SQL Server 2008 R2 database that I created as a test. I have no problem retrieving data and that has always worked. However when the program performs a cursor.execute("sql") to insert or delete a row then it does not work - no error, nothing. The response is as if I am successful updating the database but no changes are reflected. The code below essentially is creating a dictionary (I have plans for this later) and just doing a quick build of a sql insert statement (which works as I testing the entry I wrote to the log) I

Python Connection to Hive

杀马特。学长 韩版系。学妹 提交于 2019-12-04 19:51:12
问题 I installed the Hortonworks Hive ODBC driver and created a connection in the Data sources. I tested it and it worked successfully. I installed PyODBC and wrote the following code import os, sys, pyodbc; con = pyodbc.connect("DSN=MyCon") I got error Traceback (most recent call last): File "<stdin>", line 1, in <module> pyodbc.Error: ('HYC00', '[HYC00] [Hortonworks][ODBC] (11470) Transactions are not supported. (11470) (SQLSetConnnectAttr(SQL_ATTR_AUTOCOMMIT))') I also tried import pyodbc, sys,

Only first character of unicode strings getting written to csv

冷暖自知 提交于 2019-12-04 17:40:29
The nutshell of my problem is that my script cannot write complete unicode strings (retrieved from a db) to a csv, instead only the first character of each string is written to the file. eg: U,1423.0,831,1,139 Where the output should be: University of Washington Students,1423.0,831,1,139 Some background: I'm connecting to an MSSQL database using pyodbc. I have my odbc config file set up for unicode, and connect to the db as follows: p.connect("DSN=myserver;UID=username;PWD=password;DATABASE=mydb;CHARSET=utf-8") I can get data no problem, but the issue arises when I try to save query results to

How do I access AS/400 using SQLAlchemy?

二次信任 提交于 2019-12-04 17:33:42
Short version: Please tell me how to connect to AS/400s via SQLAlchemy. Long version My ultimate goal is to join data from SQL Server and AS/400 to be displayed in a Flask Python application. My approach has been to get the data from each database into Pandas dataframes, which can then be joined and output as JSON. If anyone has a better approach, feel free to leave a comment. The problem with the way I'm trying to do this is that Pandas.read_sql_query() relies on SQLAlchemy, and getting SQLAlchemy to work with AS/400 is proving quite difficult. The AS/400 is version 7.2, though another I will

Unable to connect pyODBC with SQL Server 2008 Express R2

≯℡__Kan透↙ 提交于 2019-12-04 15:57:53
问题 I am using following code to connect with SQL 2008 R2: cnxnStoneedge = pyodbc.connect("DRIVER={SQL Server};SERVER=127.0.0.1;DATABASE=myDB;UID=admin;PWD=admin") Which gives error: Error: ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. (17) (SQLDriverConnect)') args = ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNE...t exist or access denied. (17) (SQLDriverConnect)') with_traceback = <built-in method with_traceback of

How to backup a database by pyodbc

喜欢而已 提交于 2019-12-04 14:44:53
The backup statement can't be used in a transaction when it execute with pyodbc cursor. It seems that the pyodbc execute the query inside a default transaction. I have also tried to use the autocommit mode or add the commit statement before the backup statement. Both of these are not working. #can't execute the backup statement in transaction cur.execute("backup database database_name to disk = 'backup_path'") #not working too cur.execute("commit;backup database database_name to disk = 'backup_path'") Is it possible to execute the backup statement by pyodbc? Thanks in advance! -----Added

Execute SQL file with multiple statements separated by “;” using pyodbc

余生颓废 提交于 2019-12-04 07:41:16
I am currently writing a script to run multiple SQL files using Python, a little background before you mention alternative methods; this is to automate the scripts and Python is the only tools I have on our windows 2008 server. I have a script that works for one set but the issue is when the other set has two statements instead of one seperated by a ';' here is my code: import os import pyodbc print ("Connecting via ODBC") conn = pyodbc.connect('DSN=dsn', autocommit=True) print ("Connected!\n") inputdir = 'C:\\path' cursor = conn.cursor() for script in os.listdir(inputdir): with open(inputdir+

ModuleNotFoundError: No module named 'pyodbc' when importing pyodbc into py script

点点圈 提交于 2019-12-04 06:28:59
I've written a short python script which tries to import the pyodbc extension package so I can access my SQL table. import pyodbc as pyodbc cnxn = pyodbc.connect('Driver={SQL Server};' 'Server=DESKTOP-UO8KJOP;' 'Database=ExamplePFData' 'Trusted_Connection=yes;') I have definitely installed the extension by using: pip install pyodbc. And when I go to install it again, cmd says: Requirement already satisfied: pyodbc in ... and I've found the pyd file in my directories. I have also tried installing pypyodbc, which didn't work. The error I get is: Traceback (most recent call last): File "C:\Users