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的更多相关文章

  1. Linux下PHP连接MS SQLServer的办法

    Linux下PHP连接MS SQLServer的办法分析问题 本来PHP脚本读写SQLServer是没有什么问题的,在Apache for windows和Windows IIS下可以工作的很好,一般 ...

  2. php 5.4 5.5 如何连接 ms sqlserver

    https://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx

  3. MS SQLSERVER中如何快速获取表的记录总数

    在数据库应用的设计中,我们往往会需要获取某些表的记录总数,用于判断表的记录总数是否过大,是否需要备份数据等.我们通常的做法是:select count(*) as c from tableA .然而对 ...

  4. Linux下通过JDBC连接Oracle,SqlServer和PostgreSQL

    今天正好需要统计三个网站栏目信息更新情况,而这三个网站的后台采用了不同的数据库管理系统.初步想法是通过建立一个小的Tomcat webapp,进而通过JDBC访问这三个后台数据库,并根据返回的数据生成 ...

  5. 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 ...

  6. Windos 下python2.7安装 pymssql 解决方案

    最近在学python,到安装pymssql这一块遇到了不少问题. 第一:如何安装python 模块,也是最主要的问题. 可以这么理解:在安装python其它模块之前,可以先安装一个负责安装模块的模块. ...

  7. 通过win下的eclipse连接虚拟机中伪分布的hadoop进行调试

    VMware虚拟机配置Ubuntu桥接方式(Bridged)使虚拟机和宿主机能互相ping通, 通过win下的eclipse连接虚拟机中伪分布的hadoop进行调试 1.设置Bridged上网方式 V ...

  8. oracle直接读写ms sqlserver数据库(二)配置透明网关

    环境说明: 数据库版本:11gR2 透明网关版本:11g 操作系统Windows Server2008_64位 ORACLE_HOME目录:D:\app\Administrator\product\1 ...

  9. pymssql连接Azure SQL Database

    使用pymssql访问Azure SQL Database时遇到"DB-Lib error message 20002, severity 9:\nAdaptive Server conne ...

随机推荐

  1. C语言之利用递归将十进制转换为二进制

    #include<stdio.h>#include<stdlib.h>void change2(int num){  if (num != 0)   {   change2(n ...

  2. 自定义ListView分割线

    要完成自定义分割线,我们先来认识一下listview中的两个属性: android:divider 设置list 列表项的分隔条(可用颜色分隔,也可用Drawable分隔) android:divid ...

  3. 利用Azure Redis Cache构建百万量级缓存读写

    Redis是一个非常流行的基于内存的,低延迟,高吞吐量的key/value数据存储,被广泛用于数据库缓存,session的管理,热数据高速访问,甚至作为数据库方式提高应用程序可扩展性,吞吐量,和实施处 ...

  4. [TYVJ] P1238 路径

    路径 描述 Description 图是由一组顶点和一组边组成的.一条边连接两个顶点.例如,图1表示了一个有4个顶点V.5条边的图.图中,每条边e是有方向的,方向从起点到终点,并且每条边都有价值.用整 ...

  5. ng-repeat 与ng-switch的简单应用

    效果如下图所示: 使用表格显示用户信息,当点击某条用户信息时,在其下方展开一行进行展示. index.html <!DOCTYPE html> <html ng-app=" ...

  6. LeetCode_Simplify Path

    Given an absolute path for a file (Unix-style), simplify it. For example, path = "/home/", ...

  7. 【转】 树莓派学习笔记——I2C设备载入和速率设置

    原文网址:http://blog.csdn.net/xukai871105/article/details/18234075 1.载入设备 方法1——临时载入设备 sudo modprobe -r i ...

  8. Linux 挂载光驱

    Linux的硬件设备都在/dev目录下,/dev/cdrom表示光驱,挂载方法如下: 1.挂载光驱 [root@oracle ~]# mount -t iso9660 /dev/cdrom /mnt/ ...

  9. WPF可视化控件打印

    Introduction While coding an application that displays a detailed report in a ScrollViewer, it was d ...

  10. python高级编程之访问超类中的方法:super()

    # -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' #超类01 #它是一个内建类型,用于访问属于某个对象超类特性 pri ...