简体   繁体   English

使用pymssql时如何传递连接参数“ ApplicationIntent = ReadOnly”

[英]How to pass connection parameter “ApplicationIntent=ReadOnly” when using pymssql

I only have readonly access to a SQL Server db. 我只有对SQL Server数据库的只读访问权限。 How do I pass connection parameter "ApplicationIntent=ReadOnly" when using pymssql to connect to the database? 使用pymssql连接数据库时,如何传递连接参数“ ApplicationIntent = ReadOnly”? If pymssql doesn't support it, is there any other python library that I can use? 如果pymssql不支持它,还有其他可以使用的python库吗?

The only way to configure readonly connection intent with pymssql seems to be to configure freetds on which it's based, but it did not work out for me. 用pymssql配置只读连接意图的唯一方法似乎是配置基于它的freetds,但对我来说却行不通。 I've had to use pyodbc instead of pymssql 我不得不使用pyodbc而不是pymssql

from pyodbc import connect
conn = connect(
    'DRIVER={ODBC Driver 17 for SQL Server};SERVER=' + host + ';PORT=' + port + ';DATABASE='
    + database + ';UID=' + user + ';PWD=' + password + ';ApplicationIntent=ReadOnly')

Because pymssql is dependent on FreeTDS You really need to address the connection parameters to your MS-SQL server used by FreeTDS 由于pymssql依赖于FreeTDS,因此您确实需要解决FreeTDS使用的MS-SQL服务器的连接参数

Because ApplicationIntent is listed in the freetds user guide as an option you should be able to use it. 由于Applicationttent在freetds 用户指南中作为一个选项列出,因此您应该可以使用它。

pyodbc has a readonly parameter. pyodbc具有只读参数。 For example: 例如:

import pyodbc
conn = pyodbc.connect(driver='{SQL Server}', host=Server, database=Database,
                  trusted_connection='yes', user='', password='', readonly = True)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM