pyodbc

Follow up: Execute .sql files from python

喜欢而已 提交于 2019-12-22 04:46:07
问题 Over a year ago someone asked this question: Execute .sql files that are used to run in SQL Management Studio in python. I am writing a script in python that connects to a SQL server and creates and populates a database based on SQL commands in a large (several GBs) .sql file. It looks like SQLCMD requires a download and install of SQL Server Express. Are there other ways to execute a .sql file from python without requiring everyone who uses my script to download and install SQL Server? Does

does pyodbc have any design advantages over pypyodbc?

戏子无情 提交于 2019-12-22 01:53:35
问题 I know pyodbc is an older project and probably more featureful and robust, but is there anything about its design (based on components of compiled C code), that would make it preferable to a pure Python implementation, such as pypyodbc? I do a lot of ETL work and am thinking of switching from a Linux/Jython/JDBC approach to Windows/Cygwin/Python/ODBC approach. 回答1: Potential advantages of pyodbc over pypyodbc by being written in C would be: speed - see the pypyodbc wiki comparison more

pyODBC and SQL Server 2008 and Python 3

倖福魔咒の 提交于 2019-12-21 23:13:58
问题 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

Only first character of unicode strings getting written to csv

。_饼干妹妹 提交于 2019-12-21 20:56:36
问题 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

pyodbc on SQL Server - How can I do an insert and get the row ID back?

柔情痞子 提交于 2019-12-21 13:08:00
问题 I'm using pyodbc with SQL Server 2000. I want to be able to insert a row and get the auto incremented row id value back? Any ideas? Here's what I have so far: cursor.execute("insert into products(id, name) values ('pyodbc', 'awesome library')") cnxn.commit() 回答1: Sorry, I asked too soon, it's addressed in their FAQ Use "SELECT @@IDENTITY". 来源: https://stackoverflow.com/questions/2883722/pyodbc-on-sql-server-how-can-i-do-an-insert-and-get-the-row-id-back

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

点点圈 提交于 2019-12-21 13:02:36
问题 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

pyodbc.connect() works, but not sqlalchemy.create_engine().connect()

╄→гoц情女王★ 提交于 2019-12-21 03:51:03
问题 I am attempting to write a Python script that can take Excel sheets and import them into my SQL Server Express (with Windows Authentication) database as tables. To do this, I am using pandas to read the Excel files into a pandas DataFrame , I then hope to use pandas.to_sql() to import the data into my database. To use this function, however, I need to use sqlalchemy.create_engine() . I am able to connect to my database using pyodbc alone, and run test queries. This conection is done with the

Parallelizing pandas pyodbc SQL database calls

不羁的心 提交于 2019-12-21 03:44:05
问题 I am currently querying data into dataframe via the pandas.io.sql.read_sql() command. I wanted to parallelize the calls similar to what this guys is advocating: (Embarrassingly parallel database calls with Python (PyData Paris 2015 )) Something like (very general): pools = [ThreadedConnectionPool(1,20,dsn=d) for d in dsns] connections = [pool.getconn() for pool in pools] parallel_connection = ParallelConnection(connections) pandas_cursor = parallel_connection.cursor() pandas_cursor.execute(my

Pyodbc: Issue inserting into MS Access database

百般思念 提交于 2019-12-20 07:13:06
问题 I'm trying to automate data collection from the results of an online form, compile them into an Excel file, and then upload the data from the Excel file into Access. I have a Python script that does this for another database and works perfectly fine, but the same code does not work for the new database for some reason. Using pydobc, I'm able to successfully connect to the database and perform simple SELECT and INSERT statements such as: DBcursor.execute("insert into Table1(Field1, Field2)

Not able to create database using stored procedure pyodbc SQL SERVER

岁酱吖の 提交于 2019-12-20 02:34:44
问题 I am trying to call a stored procedure that creates a Database from pyodbc The Following is a minimal example of the code import pyodbc conn = pyodbc.connect("Driver={SQL Server};Server=SERVERNAME;Trusted_Connection=yes;") cursor=conn.cursor() cursor.execute("""\ DECLARE @RC int DECLARE @ClientName varchar(255) SET @ClientName = 'Test' EXECUTE @RC = [DB_NAME].[SCHEMA].[sp_NAME] @ClientName """) conn.commit() The code should ideally create a Database named ' Test ' in the SQL Server Instance.