pymssql

Insert Data to SQL Server Table using pymssql

心已入冬 提交于 2019-12-07 15:57:29
问题 I am trying to write the data frame into the SQL Server Table. My code: conn = pymssql.connect(host="Dev02", database="DEVDb") cur = conn.cursor() query = "INSERT INTO dbo.SCORE_TABLE VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" cur.executemany(query, df_sql) conn.commit() cur.close() conn.close() The dimension of the df_sql is (5860, 20) i.e. the number of columns in the data frame is same as the number of columns in the SQL Server Table. Still I

pymssql: executemany value error - expected a simple type, a tuple or a list

我与影子孤独终老i 提交于 2019-12-07 08:25:19
问题 grpidx_data=[] for i in range(0,len(data1)): grpidx_data.append((data1.loc[i,'price'],data1.loc[i,'id'])) cur.executemany("insert into grpidx values (%s,%s)",grpidx_data) I use python3.3 and pymssql. I want to import data from python to MSSQL. grpidx_data's type is list(tuple) ,like[(12,1),(34,2),...], I run the code above then got the error: ValueError: expected a simple type, a tuple or a list If I just use the data which type is list(tuple) , the code works fine. But when I use for loop

Cannot install pymssql on windows

强颜欢笑 提交于 2019-12-07 04:48:37
问题 i am trying to install pymssql as pip install pymssql i have windows 7 and python 3.5 (from anaconda) but i get Failed building wheel for pymssql i believe its related to freetds and python-dev . how do i install these on windows? Which packages would i need to install? this pip install worked just fine for python 2.7. If the pip does not work,is there any other way i can download and install pymssql? 回答1: I just went through this small bit of hell and finally got things working, here is what

Flask app with ArcGIS, Arcpy does not run

﹥>﹥吖頭↗ 提交于 2019-12-06 21:21:30
问题 I have a script that gets a table from MSSQL database and then registers it with ArcGIS. It uses several other arcpy methods as well. I tried to combine it with Flask and developed an HTML interface where you can specify tables. The script runs on console perfectly well, however, when running with Flask on http://127.0.0.1:5000/ , the arcpy functions do not run, then the app throws errors. I am using my local python directory, so I do not have any problem with importing arcpy on flask. So, I

pymssql ( python module ) unable to use temporary tables

↘锁芯ラ 提交于 2019-12-06 15:58:55
问题 This isn't a question, so much as a pre-emptive answer. (I have gotten lots of help from this website & wanted to give back.) I was struggling with a large bit of SQL query that was failing when I tried to run it via python using pymssql, but would run fine when directly through MS SQL. (E.g., in my case, I was using MS SQL Server Management Studio to run it outside of python.) Then I finally discovered the problem: pymssql cannot handle temporary tables. At least not my version, which is

Why can I connect to Azure MS SQL with tsql but not pymssql?

自闭症网瘾萝莉.ら 提交于 2019-12-06 09:47:44
Where I am today: TDSVER=7.3 tsql -H example.database.windows.net -U me -D ExampleDB -p 1433 -P notreallymypassword This does not: >>> import pymssql >>> pymssql.connect('example.database.windows.net', user='me', password='notreallymypassword', database='ExampleDB', tds_version='7.3') It fails with Traceback (most recent call last): File "<stdin>", line 1, in <module> File "pymssql.pyx", line 635, in pymssql.connect (pymssql.c:10734) File "_mssql.pyx", line 1902, in _mssql.connect (_mssql.c:21821) File "_mssql.pyx", line 577, in _mssql.MSSQLConnection.__init__ (_mssql.c:6214) File "_mssql.pyx"

Passing nulls to stored procedure in Python

自作多情 提交于 2019-12-06 09:47:37
问题 I'm using Python to call a stored procedure in my MSSQL database, but it doesn't like the "None" value passed. Is this perhaps a bug in pymssql? Or is there some way to ensure that "None" is converted to NULL? I need to be able to pass NULL. example code: cn = pymssql.connect(my connection info) cur = cn.cursor() params = range(2) params[0] = 1 params[1] = None # this needs to pass as NULL cur.callproc('mystoredproc', params) 回答1: It looks like it's a known issue. Update: I found a solution.

Update fails after repeating deadlocked query in pymssql

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 07:49:05
I'm using SQL Server with pymssql, and found that a particularly complicated SELECT query would occasionally be selected as a deadlock victim. So I wrapped it in a while loop to retry the transaction if that happens, roughly as follows: while True: try: cursor.execute('SELECT .......') count_row = cursor.fetchone(); break except Exception, tec: print "Got error: %s" % (tec) time.sleep(1) cursor.execute('UPDATE .........') self.conn.commit() It seems to work - if the SELECT hits a deadlock then it will pause for a second, retry again and get the right answer. However every time that occurs the

error: Unable to find vcvarsall.bat when installing PyMSSQL-2.0.0b1… what am i missing?

心已入冬 提交于 2019-12-06 02:44:39
Well i am trying to install PyMSSQL-2.0.0b1 and can not achieve this, get strange errors... i have tried some solutions found on Google and StackOverflow but still unable to compile... please what am i missing ? ( so i have tried : - to add --compiler=mingw32 after setup.py install build - to create a distutils.cfd file in Python27\lib\distutils\distutils.cfg with [build] compiler=mingw32 and still not working ) (also i'm on Windows 7, and i has need third party libs, must stick to 32 bits version and 2.7) here are some log with errors : C:\Users\MyUserName\Desktop\downloaded\python\pymssql-2

ubuntu 安装MYSQLDB , pymssql记录

喜你入骨 提交于 2019-12-06 00:28:44
1. 安装MYSQLDB 9 wget http://jaist.dl.sourceforge.net/project/mysql-python/mysql-python-test/1.2.4b4/MySQL-python-1.2.4b4.tar.gz tar zxvf MySQL-python-1.2.4b4.tar.gz cd MySQL-python-1.2.4b4/ sudo apt-get install libmysqlclient-dev sudo apt-get install python-dev python setup.py build python setup.py install 2. 安装pymssql 28 apt-get install easy_install 29 ls 30 tar zxvf -f pymssql.tar.gz 31 tar -zxvf pymssql-2.0.0b1-dev-20130403.tar.gz 32 cd pymssql-2.0.0b1-dev-20130403/ 33 ls 34 apt-get install Cpython 35 apt-get install cpython 36 apt-get install freetds 37 cd .. 38 ls 39 tar zxvf freetds