从SQL server 2014将数据加载到Python中

从SQL server 2014将数据加载到Python中,python,sql-server,python-3.x,Python,Sql Server,Python 3.x,我有以下代码,我想使用Jupyter笔记本将数据加载到Python中: import pandas as pd import pyodbc conn = ( r'DRIVER={SQL Server};' r'SERVER=DESKTOP-ULQTFDK\SQLSERVER2014;' r'DATABASE=AdventureWorks2014;' r'Trusted_Connection=yes;' ) conn = pyodbc.connect(conn)

我有以下代码,我想使用Jupyter笔记本将数据加载到Python中:

import pandas as pd
import pyodbc

conn = (
    r'DRIVER={SQL Server};'
    r'SERVER=DESKTOP-ULQTFDK\SQLSERVER2014;'
    r'DATABASE=AdventureWorks2014;'
    r'Trusted_Connection=yes;'
)
conn = pyodbc.connect(conn)
#df=pd.read_sql('select * from Person.Person',conn_str)

if conn:
    print("Yes, we are connected ")
当我像上面一样测试连接时,它显示它已连接 但是当我试图像下面这样查询数据帧时

df=pandas.read_sql('select * from Person.Person',conn)
df.shape
我得到了这个错误:

Error                                     Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\sql.py in execute(self, *args, **kwargs)
   1403             else:
-> 1404                 cur.execute(*args)
   1405             return cur

Error: ('HY000', '[HY000] [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt (0) (SQLExecDirectW)')

During handling of the above exception, another exception occurred:

DatabaseError                             Traceback (most recent call last)
<ipython-input-36-1bc707d0534c> in <module>()
----> 1 df=pandas.read_sql('select * from Person.Person',conn
错误回溯(最近一次调用上次)
C:\ProgramData\Anaconda3\lib\site packages\pandas\io\sql.py in execute(self,*args,**kwargs)
1403其他:
->1404当前执行(*args)
1405返回电流
错误:('HY000','[HY000][Microsoft][ODBC SQL Server驱动程序]连接正忙于处理另一个hstmt(0)(SQLExecDirectW)'的结果)
在处理上述异常期间,发生了另一个异常:
数据库错误回溯(上次最近调用)
在()
---->1 df=pandas.read_sql('select*from Person.Person',conn

有什么帮助吗?

您将导入的熊猫作为
pd
使用
pd

df=pd.read_sql('select * from Person.Person',conn)
df.shape

您将导入的熊猫作为
pd
使用
pd

df=pd.read_sql('select * from Person.Person',conn)
df.shape