I have the following code that I want to load data into Python using Jupyter Notebook:
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 ")
When I test the connection just like above it shows that it is connected but when I try to query the data frame like bellow
df=pandas.read_sql('select * from Person.Person',conn)
df.shape
I'm getting this error:
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
Any help?