python访问sqlserver示例
时间:2022-07-15 07:25:01
最近遇到了Python访问SqlServer的问题,这里总结下。
一、Windows下配置Python访问Sqlserver
环境:Windows 7 + Sqlserver 2008
1、下载并安装pyodbc
下载地址:http://code.google.com/p/pyodbc/downloads/list
2、访问SqlServer
>>> import pyodbc
>>>cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=192.168.1.100\\sql;DATABASE=testDB;UID=sa;PWD=myPassword')
>>>cursor = cnxn.cursor()
>>>cursor.execute("select * from Tb")
二、Linux下配置Python访问SqlServer
环境:CentOS 6.2 + Sqlserver 2008
1、安装freetds:
yum install freetds*
2、安装pyodbc:
yum install pyodbc
修改odbc配置:
vi /etc/odbcinst.ini
添加FreeTDS驱动:
[SQL Server]
Description = FreeTDS ODBC driver for MSSQL
Driver = /usr/lib/libtdsodbc.so
Setup = /usr/lib/libtdsS.so
FileUsage = 1
3、测试
#python
>>> import pyodbc
>>>cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=192.168.1.100\\sql;DATABASE=testDB;UID=sa;PWD=myPassword')
>>>cursor = cnxn.cursor()
>>>cursor.execute("select * from Tb")
标签:python,sqlserver
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
戴尔是如何设计新官网首页的
2008-07-08 19:02:00
![](https://img.aspxhome.com/file/UploadPic/20087/8/20087819552621s.jpg)
你是真正的用户体验设计者吗? Ⅴ
2008-04-19 18:32:00
![](https://img.aspxhome.com/file/UploadPic/20084/19/2008419215352323s.jpg)
多种网页弹出窗口代码
2007-11-24 21:13:00
Python中给List添加元素的4种方法分享
2023-09-12 04:33:58
触手生春【4.13】CSS中的伪元素选择符
2008-11-11 13:10:00
![](https://img.aspxhome.com/file/UploadPic/200811/11/o2008113223147-93s.jpg)
使用Python和Prometheus跟踪天气的使用方法
2021-05-15 14:31:05
python中os操作文件及文件路径实例汇总
2023-03-20 23:54:09
PHP+MYSQL不恶补十句话
2009-12-02 10:09:00
python中的np.argmax() 返回最大值索引号
2022-08-07 14:22:57
![](https://img.aspxhome.com/file/2023/0/67860_0s.png)
IE6/7关于 Absolute Position 、relative 的一些意外
2008-11-27 11:34:00
动态载入树 (ASP+数据库)
2010-05-27 12:20:00
ASP利用 xmlhttp 分块上传文件
2007-11-01 22:55:00
ASP实现下载系统防盗链方法
2008-02-01 14:05:00
巧用weui.topTips验证数据的实例
2023-08-12 03:00:51
![](https://img.aspxhome.com/file/2023/2/55982_0s.png)
我所理解的网页推广设计的几个要点
2011-01-25 12:37:00
![](https://img.aspxhome.com/file/UploadPic/20111/25/javascript-selectors3-23s.jpg)
CSS pointer-events下层元素被点击
2010-04-11 22:31:00
Appium自动化测试实现H5页面元素定位
2023-06-22 02:25:53
![](https://img.aspxhome.com/file/2023/0/60740_0s.png)
javascript面向对象技术基础(二)
2010-02-07 13:09:00
python 字典操作提取key,value的方法
2021-06-01 04:40:39
![](https://img.aspxhome.com/file/2023/0/67250_0s.jpg)
Oracle10g 安装方法
2009-06-19 17:50:00