win 下python2.7 pymssql连接ms sqlserver 2000
python DB-API 连接mysql 要用到库pymssql 下载请到https://pypi.python.org/pypi/pymssql/2.0.1我这里下载的是ms windows installer版本exe文件,直接运行就可以了,whl和egg格式的看不懂怎么安装.
下载完,试着连接到本机的pubwin数据库写了一句查询,很方便的样子
# -*- coding:gbk -*-
import pymssql
try:
con=pymssql.connect(host='.',user='sa',password='sa',database='local')
cur=con.cursor()
cur.execute('select uniqueid,levelid from mem_localmemberbaseinfo')
for uniqueid,levelid in cur.fetchall():
print 'uniqueid: %s,levelid: %s' % (uniqueid,levelid)
print cur.rowcount
cur.close()
con.close() except:
print 'sql Error'
con=pymssql.connect(host='.',user='sa',password='sa',database='local'),百度了一下,python DB-API连接数据库都是用这个格式标准。host可以用ip:1433的格式 带端口。
fetchall():用来取回cur的所有数据,fetchone 是只取回一行数据,上面的查询,同样可以用detchone实现:
# -*- coding:gbk -*-
import pymssql
try:
con=pymssql.connect(host='127.0.0.1:1433',user='sa',password='sa',database='local')
cur=con.cursor()
cur.execute('select uniqueid,levelid from mem_localmemberbaseinfo order by uniqueid')
rowcount=0
while 1:
row=cur.fetchone()
if row==None:break
print "uniqueid: %s,levelid %s" % (row[0],row[1])
rowcount+=1
print rowcount
cur.close()
con.close() except:
print 'sql Error'
参考:http://tech.it168.com/a2009/1014/759/000000759444.shtml(利用MySQLdb 对DB-API的详细介绍,推荐)
win 下python2.7 pymssql连接ms sqlserver 2000的更多相关文章
- Linux下PHP连接MS SQLServer的办法
Linux下PHP连接MS SQLServer的办法分析问题 本来PHP脚本读写SQLServer是没有什么问题的,在Apache for windows和Windows IIS下可以工作的很好,一般 ...
- php 5.4 5.5 如何连接 ms sqlserver
https://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx
- MS SQLSERVER中如何快速获取表的记录总数
在数据库应用的设计中,我们往往会需要获取某些表的记录总数,用于判断表的记录总数是否过大,是否需要备份数据等.我们通常的做法是:select count(*) as c from tableA .然而对 ...
- Linux下通过JDBC连接Oracle,SqlServer和PostgreSQL
今天正好需要统计三个网站栏目信息更新情况,而这三个网站的后台采用了不同的数据库管理系统.初步想法是通过建立一个小的Tomcat webapp,进而通过JDBC访问这三个后台数据库,并根据返回的数据生成 ...
- c# 使用MS SqlServer,连接成功,但是还报异常A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0。。。。
c# 使用MS SqlServer,连接成功,但是还报异常A connection was successfully established with the server, but then an ...
- Windos 下python2.7安装 pymssql 解决方案
最近在学python,到安装pymssql这一块遇到了不少问题. 第一:如何安装python 模块,也是最主要的问题. 可以这么理解:在安装python其它模块之前,可以先安装一个负责安装模块的模块. ...
- 通过win下的eclipse连接虚拟机中伪分布的hadoop进行调试
VMware虚拟机配置Ubuntu桥接方式(Bridged)使虚拟机和宿主机能互相ping通, 通过win下的eclipse连接虚拟机中伪分布的hadoop进行调试 1.设置Bridged上网方式 V ...
- oracle直接读写ms sqlserver数据库(二)配置透明网关
环境说明: 数据库版本:11gR2 透明网关版本:11g 操作系统Windows Server2008_64位 ORACLE_HOME目录:D:\app\Administrator\product\1 ...
- pymssql连接Azure SQL Database
使用pymssql访问Azure SQL Database时遇到"DB-Lib error message 20002, severity 9:\nAdaptive Server conne ...
随机推荐
- libc++abi.dylib: terminate_handler unexpectedly threw an exception错误小结
说法一: 我们在运行xcode工程时,有时候会遇到”libc++abi.dylib: terminate_handler unexpectedly threw an exception”错误,app莫 ...
- QtCreator调试传入运行参数
QtCreator是非常不错的IDE,最近在做的Qt命令行应用,因为调试的环境不同等问题,需要在调试的时候为 main() 传入参数.度娘了半天,没找到方法,只能自力更生.后来在“项目-构建和运行-运 ...
- Windows下连接php5.3+sql server2008
php连接sql server真是一件闹心的事, 折腾了许久,今天有了点起色,还是不错的. mssql extension is not available anymore on Windows wi ...
- 2013第46周四xml作为WS两端中间测试文件
今天又到了11点多才开始写随笔记录,有点惭愧,加班回来到现在已经近2小时了,而我此刻才进入正题,之前的时间都跟MM聊天了,或许是单身久了,居然在个人情感方面感觉自己很out了,不想这些了,重点是回顾下 ...
- 制作安装包工具NSIS
NSIS 下载地址: http://nsis.sourceforge.net/Download 编辑工具:NIS Edit 下载地址: http://soft.hao123.com/soft/appi ...
- 页和区 sql server
原文地址:http://msdn.microsoft.com/zh-cn/library/ms190969.aspx SQL Server 中数据存储的基本单位是页.为数据库中的数据文件(.mdf 或 ...
- Linux用户基础
http://itercast.com/lecture/21 操作系统通过用户.组概念来管理使用计算机的人 用户代表一个使用计算机的使用者,操作系统通过用户概念限制一个使用者能够访问的资源 组用来组织 ...
- POJ-2955括号匹配问题(区间DP)
Brackets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4834 Accepted: 2574 Descript ...
- 《Algorithms 4th Edition》读书笔记——3.1 符号表(Elementary Symbol Tables)-Ⅳ
3.1.4 无序链表中的顺序查找 符号表中使用的数据结构的一个简单选择是链表,每个结点存储一个键值对,如以下代码所示.get()的实现即为遍历链表,用equals()方法比较需被查找的键和每个节点中的 ...
- Unable to resolve target 'android-14' 解决办法
学习安卓的时候用Eclipse导入工程之后出现Unable to resolve target 'android-14' 这样的问题,代码确定没有问题,因为是从网上教程下载的示例代码,上网搜索了一下, ...