pyodbc

INSERT INTO Access database from pandas DataFrame

≯℡__Kan透↙ 提交于 2019-12-06 12:19:53
问题 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,

pyodbc: query results to CSV?

↘锁芯ラ 提交于 2019-12-06 11:05:58
问题 I am using pyodbc to access a database and print the query results. How do I use pyodbc to print the whole query result including the columns to a csv file? CODE: import pyodbc cnxn = pyodbc.connect( #DATA BASE NAME IS HERE, HID FOR PRIVACY ) cursor = cnxn.cursor() cursor.execute(""" #COMMAND GOES HERE """) row = cursor.fetchall() #FETCHES ALL ROWS cnxn.commit() cnxn.close() 回答1: How do I use pyodbc to print the whole query result including the columns to a csv file? You don't use pyodbc to

pyodbc connection to mdb file

主宰稳场 提交于 2019-12-06 09:14:32
I am trying to connect pyodbc to an mdb file. I have searched this site and tried a number of things without success. Here is an overview of my system. Windows 7 Ultimate Service Pack 1 64 Operating System Python 3.4.0 installed in C:\Python34\ installed using python-3.4.0.amd64.msi pyodbc 3.0.7 installed using pyodbc-3.0.7.win-amd64-py3.4.exe Installed AccessDatabaseEngine.exe 14.0.6119.5000 MS 2007 Office System Driver Control Panel\All Control Panel Items\Administrative Tools Data Sources (ODBC) set to %windir%\SysWOW64\odbcad32.exe Permissions in the Registry for my user profile set to

Python pyodbc connect to ms access database

痴心易碎 提交于 2019-12-06 08:37:09
I am trying to connect my access database so I can dump my data into the table in the database. This the code I use: import pyodbc access_database_file = "C:\\Users\\Moyp\\DataPointe.accdb" ODBC_CONN_STR = 'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=%s;' %access_database_file conn = pyodbc.connect(ODBC_CONN_STR) However, I keep receiving this error: Traceback (most recent call last): File "C:\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 3035, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-6-a4daec7c49a9>", line 1, in <module>

Error connecting to MS SQL Server using pyODBC, unixODBC and FreeTDS (on a Mac)

懵懂的女人 提交于 2019-12-06 06:03:01
I am getting an error when trying to connect to a MS SQL server in python, using the pyODBC --> unixODBC --> FreeTDS --> MS SQL stack. I’ve spent a lot of time on this, and there are some great resources if you’ve reached this question with more fundamental problems getting a connection to work here and here . However, my question is regarding an error that (I think) is very close to the finish line of this very frustrating experience. Specifically, this code in jupyter notebook: pyodbc.connect( 'DRIVER=/usr/local/lib/libtdsodbc.so;' 'SERVER=MyServerIP;' 'PORT=1433;' 'DATABASE= DatabaseName;'

Writing python (pandas) Data Frame to SQL Database Error

[亡魂溺海] 提交于 2019-12-06 05:20:12
I am trying to put a python data frame to a MS SQL DB and I am getting the following error FUNCTION def put_to_server(df): # df is a pandas data frame server="KORNBSVM04\MSSQLSERVER2012" Driver="{SQL Server}" userid='' pswd='' cnxn = pyodbc.connect(driver=Driver, server=server, database="CIHOTLINE",uid=userid, pwd=pswd) cur=cnxn.cursor() df.to_sql(name='dbo.test',con=cnxn) ERROR File "C:\Python27\lib\site-packages\pandas\core\generic.py", line 950, in to_sql index_label=index_label) File "C:\Python27\lib\site-packages\pandas\io\sql.py", line 475, in to_sql index_label=index_label) File "C:

Set connection settings with Pyodbc + UnixODBC + FreeTDS

不想你离开。 提交于 2019-12-06 04:34:53
I have a setup using Pyodbc, UnixODBC and FreeTDS, but somewhere in there some options are being set and I don't know where. According to SQL Server Management Studio, my program is sending some settings when it opens the connection: set quoted_identifier off set ansi_padding off set ansi_nulls off ... But I need a different set of settings: set quoted_identifier on set ansi_padding on set ansi_nulls on ... Is there any way to change this? If I can't do it with my current setup, are there any other libraries I could use in Python that would let me change it (preferably using the Python

Python in Windows: large number of inserts using pyodbc causes memory leak

和自甴很熟 提交于 2019-12-06 04:23:39
I am trying to populate a MS SQL 2005 database using python on windows. I am inserting millions of rows, and by 7 million I am using almost a gigabyte of memory. The test below eats up 4 megs of RAM for each 100k rows inserted: import pyodbc connection=pyodbc.connect('DRIVER={SQL Server};SERVER=x;DATABASE=x;UID=x;PWD=x') cursor=connection.cursor() connection.autocommit=True while 1: cursor.execute("insert into x (a,b,c,d, e,f) VALUES (?,?,?,?,?,?)",1,2,3,4,5,6) mdbconn.close() Hack solution: I ended up spawning a new process using the multiprocessing module to return memory. Still confused

the first argument to execute must be a string or unicode query

血红的双手。 提交于 2019-12-06 03:02:50
I am trying to upload a blob data to ms-sql db, using pyodbc. And I get "the first arguement to execute must be a string or unicode query" error. The code is; file = pyodbc.Binary(open("some_pdf_file.pdf", "r").read()) cur.execute("insert into BlobDataForPDF(ObjectID, FileData, Extension) values ('1', " + file + ", '.PDF')") cur.commit() The first arguement, ObjectID, is sent as string. I dont see any problems but am I missing something? Use parameterized insert: file = pyodbc.Binary(open("some_pdf_file.pdf", "r").read()) sql = "insert into BlobDataForPDF(ObjectID, FileData, Extension) values

Correct mt.exe syntax to resolve pyodbc import problems

时光怂恿深爱的人放手 提交于 2019-12-06 01:59:00
I'm deploying a Python app on Windows for the first time (Apache & mod_wsgi/Flask/Sqlalchemy). I'd like to use pyodbc to get Sqlalchemy talking to mssql. I was able to install a binary build of pyodbc with no problem, and it works when I use it from the command line. However, mod_wsgi is logging import errors when it hits import pyodbc This thread on the pyodbc issue tracker describes my issue exactly, and seems to implicate Windows manifests. However, I can't figure out how to use mt.exe to resolve it. In PowerShell: C:\my\site-packages> C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\mt.exe