pyodbc

Remote connection to MS SQL - Error using pyodbc vs success using SQL Server Management Studio

我的未来我决定 提交于 2019-12-20 00:59:31
问题 I have a MS SQL database in the same network but in other computer. Using the SQL Server Management Studio (SSMS) Express, I can find the database and connect without problems. But when I use pyodbc to connect to the same server using: import pyodbc server = r"xxxER\xxxSQLSERV" db = "xxxDB" user = "xxx" password = "xxxx" conn = pyodbc.connect('DRIVER={SQL Server};SERVER='+server + ';DATABASE=' + db +';UID=' + user + ';PWD=' + password) I get following error: pyodbc.OperationalError: ('HYT00',

pyodbc/sqlAchemy enable fast execute many

亡梦爱人 提交于 2019-12-19 03:57:08
问题 In response to my question How to speed up data wrangling A LOT in Python + Pandas + sqlAlchemy + MSSQL/T-SQL I was kindly directed to Speeding up pandas.DataFrame.to_sql with fast_executemany of pyODBC by @IljaEverilä. NB For test purposes I am only reading/writing 10k rows. I added the event listener and a) the function is called but b) clearly executemany is not set as the IF fails and cursor.fast_executemay is not set. def namedDbSqlAEngineCreate(dbName): # Create an engine and switch to

How to get a SQL Server stored procedure return value using pyodbc?

纵饮孤独 提交于 2019-12-19 03:45:29
问题 My team's using a python-based wiki server that calls stored procedures on a SQL Server database. Ideally, we'd like to return integer values (1,0,-1) from the stored procedure to show basic results. According to a 2008 thread on Google Groups, return values aren't supported by pyodbc, so the alternative is to SELECT the result as a row and check it instead. Is that still the case? Is there a (supported and documented) programmatic way to check the return value from SQL stored procedures? (If

Cannot connect to Access DB using pyodbc

 ̄綄美尐妖づ 提交于 2019-12-19 03:42:08
问题 I've been beating my head against this for a few days now. I'm trying to use pyodbc to connect to a Microsoft Access DB, and I can't seem to get the connection string right or something. This is what I'm using: cnxn = pyodbc.connect(r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Path\to\file.accdb') I keep getting the error: Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnectW)') Even though

basic pyodbc bulk insert

隐身守侯 提交于 2019-12-18 12:17:07
问题 In a python script, I need to run a query on one datasource and insert each row from that query into a table on a different datasource. I'd normally do this with a single insert/select statement with a tsql linked server join but I don't have a linked server connection to this particular datasource. I'm having trouble finding a simple pyodbc example of this. Here's how I'd do it but I'm guessing executing an insert statement inside a loop is pretty slow. result = ds1Cursor.execute(selectSql)

Python pip unable to locate pyodbc

帅比萌擦擦* 提交于 2019-12-18 10:42:54
问题 Using virtualenv and just trying to install pyodbc. All resources I can find claim this should be extremely straightforward. After all the basic installs of MySQL, etc., just do: pip install pyodbc However, I am seeing a very strange error. It has nothing (as far as I can tell) to do with missing libraries, and after Googling for this sort of error for a long time, I can't find anything constructive on it at all. (local-dev)espears@espears-w ~ $ pip install pyodbc Downloading/unpacking pyodbc

How to convert Pandas DataFrame column from Pandas datetime64[ns] to Pyodbc SQL_Timestamp

做~自己de王妃 提交于 2019-12-18 09:47:19
问题 I am trying to populate Pandas Dataframe into empty MS Access 2016 table via pyodbc. I get the following error message when I try to insert Dataframes into Access: pyodbc.dataerror: ('22008', [ODBC Microsoft Access Driver]Datetime field overflow . Research showed that MS Access Date/Time datatypes correspond to ODBC SQL_TIMESTAMP datatypes. I tried the following to convert datetime64[ns] to SQL_TIMESTAMP: import datetime cursor.execute("INSERT sql statement...VALUES(?)", datetime.datetime

pyodbc.ProgrammingError: No results. Previous SQL was not a query, when executing multiple statements at once

≯℡__Kan透↙ 提交于 2019-12-18 08:56:29
问题 i am dealing with sql server database, where i have a table named ' table1 ' containing 1 column and 1 row exp_num 0 I am trying to update the 0 value exp_num column to +1 and also return old experiment and updated experiment. For this i am using declare statements. DECLARE @UpdateOutput1 table (Oldexp_num int,Newexp_num int); UPDATE get_exp_num SET exp_num = exp_num+1 OUTPUT DELETED.exp_num, INSERTED.exp_num INTO @UpdateOutput1; select * from @UpdateOutput1 When i'm running this in SQL

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

怎甘沉沦 提交于 2019-12-18 06:48:14
问题 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

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

╄→尐↘猪︶ㄣ 提交于 2019-12-18 04:38:10
问题 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