sql-server - 从 Jupiter Notebook 中的 SQL Server 2014 读取数据
问题描述
我正在尝试从 sql server 2014 AdventureWorks2014 数据库中读取数据。我在 python jupyter 笔记本中编写了以下代码
import pandas
import pyodbc
#Connection sting Diver, server, database, Authentication
connection = pyodbc.connect("Driver ={ODBC Driver 13 for SQL Server};"
"Server =JONWAY01\SQLSERVER2014;"
"Database=AdventureWorks2014;"
"Trusted_Connection=yes;")
#create df
df = pandas.read_sql('SELECT *FROM HumanResources.Employee',connection)
connection.close()
df.head()
当我运行代码时它给出错误
InterfaceError Traceback (most recent call last)
<ipython-input-15-8e663d2a3f56> in <module>
2 import pyodbc
3 #Connection sting Diver, server, database, Authentication
----> 4 connection = pyodbc.connect("Driver ={ODBC Driver 13 for SQL Server};"
5 "Server =JONWAY01\SQLSERVER2014;"
6 "Database=AdventureWorks2014;"
InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
我做错了什么吗?请帮忙谢谢
解决方案
信不信由你,关键字后面不能有空格Driver
。如下更改它,只要您安装了 ODBC 驱动程序,您就可以开始使用了。
connection = pyodbc.connect("Driver={ODBC Driver 13 for SQL Server};"
"Server=JONWAY01\SQLSERVER2014;"
"Database=AdventureWorks2014;"
"Trusted_Connection=yes;")
推荐阅读
- angular - 嵌套表单:提交时不验证内部表单
- assembly - nasm 段错误 macos mojave 10.14.1
- arrays - Swift:在数组中追加项目的算法
- javascript - VS Code 如何将 HTML 组合成 .JS 文件?
- css - 图像不适合引导程序 4 中的轮播
- jtable - 如何减少自定义 DefaultTableCellRenderer(斑马色表)的 cpu 资源?
- node.js - Telegram 机器人的循环问题
- python-3.x - 具有 for 循环值的多个浮点输入()
- javascript - 用 javascript 模板文字推断变量的正确语法?
- java - 更新对象列表中对象的值