pymssql

python连接sql server方法总结

亡梦爱人 提交于 2020-01-18 09:39:38
前几天想把爬取的招聘数据存到sql server数据库中,但是python程序一直连不上sql server,也想上网找博客来解决问题,但是千篇一律,讲得太简单并不能解决问题,最后自己仔细从sql server的登录设置、配置管理器、端口来着手考虑自己解决问题。现在总结一下方法。 1. 配置管理器 首先需要登录启动相应的数据库实例,一开始的弹窗在还未启动服务器实例的时候是无法登录连接到对象资源管理器的,所以需要关闭一开始的弹窗,手动在本地服务器组中选择安装好的实例,右键点击“服务控制”启动,然后才可以登录连接其对象资源管理器。 已连接的数据库实例也要确保能使用sql server角色的方式登录 在安全性查看数据库的用户,给用户设置好密码,确保你所用到的用户能登陆数据库。可以使用这个用户点击“连接”输入用户名和密码测试一下你所用的的用户是否真的能登上数据库 2. 配置管理器 在配置管理器的SQL Server网络配置中要启用相应数据库实例的TCP/IP。 3. 使用pymssql或pyodbc连接sql server 我还是比较推荐使用pyodbc的,因为pyodbc的文档更为丰富,异常报错信息也要比pymssql明确,更有利于debug。 pymssql conn = mssql . connect ( host = 'localhost' , server = r

python连接SqlServer数据库

ぃ、小莉子 提交于 2020-01-16 17:44:11
#!/usr/bin/env python # -*- coding:utf-8 -*- import pymssql #引入pymssql模块 def conn(): connect = pymssql.connect('(local)', 'admin', '123456', 'we') #服务器名,账户,密码,数据库名 if connect: print("连接成功!") return connect if __name__ == '__main__': conn = conn() 复制,然后执行即可 此处需要下载引入pymssql插件 来源: CSDN 作者: 瓜小胖的一生 链接: https://blog.csdn.net/KingCherry/article/details/104006481

Connect to MSSQL in Python2.7.11 (Windows 10 Professional)

你说的曾经没有我的故事 提交于 2020-01-07 02:35:29
问题 I tried to connect to a remote MSSQL server by using pymssql package but then I get "ImportError: No module named pymssql". Yes, I have done a pip install pymssql which worked. I also looked into installing Cython but it seems such install would give more headaches, so not worth to attempt with such. If I am not totally wrong, pymssql recuires Cython. The OS I am using is Windows 10 Professional. Remote connection to MSSQL does work, since at the other side of the office they are connected to

SQLAlchemy connects to SQLServer using Windows Authenticaton with pymssql driver

两盒软妹~` 提交于 2020-01-05 07:55:09
问题 I can use pymssql to connect to SQLServer using Windows Authentication : conn = pymssql.connect(host='..', database='..', trusted=True) But how could I use SQLAlchemy to connect to SQLServer using Windows Authenticaton with pymssql driver? The example given by SQLAlchemy is: mssql+pymssql://<username>:<password>@<freetds_name> Since I use Windows Authentication, I cannot manually set the username and password. 回答1: I do not have pymssql to check, but try the version below: mssql+pymssql://

SqlAlchemy+pymssql. Will raw parametrized queries use same execution plan?

我怕爱的太早我们不能终老 提交于 2020-01-04 13:17:11
问题 In my application I have parametrized queries like this: res = db_connection.execute(text(""" SELECT * FROM Luna_gestiune WHERE id_filiala = :id_filiala AND anul=:anul AND luna = :luna """), id_filiala=6, anul=2010, luna=7).fetchone() Will such query use same query execution plan if I run it in loop with different parameter values? 回答1: It seems unlikely. pymssql uses FreeTDS, and FreeTDS performs the parameter substitution before sending the query to the server, unlike some other mechanisms

SqlAlchemy+pymssql. Will raw parametrized queries use same execution plan?

六眼飞鱼酱① 提交于 2020-01-04 13:14:22
问题 In my application I have parametrized queries like this: res = db_connection.execute(text(""" SELECT * FROM Luna_gestiune WHERE id_filiala = :id_filiala AND anul=:anul AND luna = :luna """), id_filiala=6, anul=2010, luna=7).fetchone() Will such query use same query execution plan if I run it in loop with different parameter values? 回答1: It seems unlikely. pymssql uses FreeTDS, and FreeTDS performs the parameter substitution before sending the query to the server, unlike some other mechanisms

Python with MS SQL - truncated output

家住魔仙堡 提交于 2019-12-30 23:07:04
问题 I try to connect to MSSQL DB with python from Linux box ( Python 2.7 , Ubuntu 11.04 ) . Output that I receive is truncated to 500 characters. Please, see script and configs below. How it could be resolved? The problem I suppose in ODBC driver or near it. The code (pyodbc, pymssql): conn = pymssql.connect(host='my_remote_host', user='ro_user', password='password', database='current', as_dict=True) cur = conn.cursor() cur.execute(sql) for i in cur: print i conn.close() cnxn = pyodbc.connect

Python with MS SQL - truncated output

烈酒焚心 提交于 2019-12-30 23:06:21
问题 I try to connect to MSSQL DB with python from Linux box ( Python 2.7 , Ubuntu 11.04 ) . Output that I receive is truncated to 500 characters. Please, see script and configs below. How it could be resolved? The problem I suppose in ODBC driver or near it. The code (pyodbc, pymssql): conn = pymssql.connect(host='my_remote_host', user='ro_user', password='password', database='current', as_dict=True) cur = conn.cursor() cur.execute(sql) for i in cur: print i conn.close() cnxn = pyodbc.connect

Adaptive server connection failed (DB-Lib error message 20002, severity 9)

核能气质少年 提交于 2019-12-29 01:43:14
问题 I'm sure this issue has been raised an uncountable number of times before but perhaps, someone could still help me. I am using pymssql v2.1.3 with Python 2.7.12 and the code that I used several times until yesterday to write data to my Azure SQL DB has somehow decided not to work anymore - for no apparent reason. The firewall is set, my IP is in the whitelist, I can connect to the database using SQL Server Management Studio and query the data but I still keep getting this error when

How do I specify Transaction Isolation Level for MS SQL backend in Sql Alchemy Python

走远了吗. 提交于 2019-12-25 07:05:09
问题 How do I set transaction level READ UNCOMMITED for all queries done through a SQL Alchemy engine object? I set the isolation_level argument as notated here: http://docs.sqlalchemy.org/en/latest/core/engines.html#sqlalchemy.create_engine.params.isolation_level by passing it into create_engine like so: my_eng = create_engine(db_conn_string, isolation_level='READ_UNCOMMITTED') but for my backend (MS SQL Server) I get the following error, perhaps unsurprisingly as the docs do say it is dialect