使用Python连接SQL Server数据库

1、安装sqlserver

用的是sqlserver2012的版本

网上很多,参考下
https://blog.csdn.net/weixin_44889709/article/details/123769722

2、安装python3.7及以下环境

尝试安装python3.8的环境不能连接成功

conda create -n pytorch python=3.7

3、安装sqlserver的python包

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pymssql

4、新建数据库

用sqlserver管理工具

连接数据库

新建数据库

5、可连接成功了

其中dbname就是上面创建的sa数据库名

# 连接数据库
    def getconn(self):
        return pymssql.connect(database=self.dbname,user=user,password=password,host=host,port=port)

作者:GIS从业者

物联沃分享整理
物联沃-IOTWORD物联网 » 使用Python连接SQL Server数据库

发表回复