python - 使用 pandas 读取“只读”SQL
问题描述
我试图使用以下代码将 sql 表读入 pandas 数据框:
import pandas as pd
import pyodbc as pb
conn = pb.connect(
'DRIVER={SQL Server Native Client 11.0};'
'SERVER=server_name;'
'DATABASE=db;'
'Trusted_Connection=yes'
)
sql_builder = pd.read_sql_query(
'SELECT * from schema.table',conn
)
df=pd.DataFrame(sql_builder)
它有以下错误:
Traceback (most recent call last):
File "c:/Users/user/Desktop/SQL.py", line 6, in <module>
'DRIVER={SQL Server Native Client 11.0};'
pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][SQL Server Native Client 11.0][SQL Server]The target database ('db') is in an availability group and is
currently accessible for connections when the application intent is set to read only. For more information about application intent, see SQL Server Books Online. (978) (SQLDriverConnect); [42000] [Microsoft][SQL Server Native Client 11.0][SQL Server]The target database ('dbDepot') is in an availability group and is currently accessible for connections when the application intent is set to read only. For more information about application intent, see SQL Server Books Online. (978)")
我的问题是,如何将只读表读入 pandas 数据框?
解决方案
尝试将连接上的自动提交设置为 True 以防止在连接上发送开始事务。
推荐阅读
- javascript - 从 React 外部访问第三方 React 应用程序状态
- python - 如何使用 python 检查通过 ADB 的 IP 连接是否成功?
- javascript - 如何比较两张工作表并删除/添加第 1 行中具有不同值的任何列?谷歌脚本
- python - Python将SQL查询的输出保存到Excel
- markdown - 在 Jekyll 中用括号和特殊字符链接
- php - PHP7 未定义的类常量触发 php7:notice
- sql-server - 将参数传递给嵌套过程或创建临时表并检查表是否存在
- angular - 如何为 Angular CLI 设置 bazel 选项 --output_user_root
- amazon-web-services - 有没有办法通过 API Gateway 发送大文件?
- javascript - 方法中的 JavaScript 事件侦听器