473,441 Members | 1,514 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,441 software developers and data experts.

I am trying to get an SQL Table into a Pandas DataFrame and get a cursor error

I am just trying to get an SQL Server table into a Pandas DataFrame and copied this code from the internet, obviously added my local details and credentials ie XXXX etc. Which I think works OK. When I try to run the next bit I get the messages below.

As a newbee please can someone help me as I have been going round in circles for 3 hours now!!!!! Many thanks

Expand|Select|Wrap|Line Numbers
  1. import pyodbc
  2. import pandas as pd
  3.  
  4. conn = pyodbc.connect
  5. (r'DRIVER={ODBC Driver 13 for SQL Server};' +
  6.  ('SERVER={server},{port};'   +
  7.   'DATABASE={database};'      +
  8.   'UID={username};'           +
  9.   'PWD={password}').format(
  10.                 server= 'XXXXXX',
  11.                   port= 'XXXXXX',
  12.               database= 'XXXXXXX',
  13.               username= 'XXXXXXX',
  14.               password= 'XXXXXXXXX'))
  15.  
  16. SQL = "select [PASID], [TeamReferralStartDate], [TeamReferralEndDate], ]TeamCodeDescription] FROM live.tbl_ref_Mart"
  17.  
  18. SQL_Query = pd.read_sql_query (SQL ,conn)
Above code gives me


Expand|Select|Wrap|Line Numbers
  1.   File "<ipython-input-68-57057e3d73eb>", line 3, in <module>
  2.     SQL_Query = pd.read_sql_query (SQL ,conn)
  3.  
  4.   File "C:\Users\SMITHAL\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\io\sql.py", line 332, in read_sql_query
  5.     chunksize=chunksize,
  6.  
  7.   File "C:\Users\SMITHAL\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\io\sql.py", line 1645, in read_query
  8.     cursor = self.execute(*args)
  9.  
  10.   File "C:\Users\SMITHAL\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\io\sql.py", line 1590, in execute
  11.     cur = self.con.cursor()
  12.  
  13. AttributeError: 'builtin_function_or_method' object has no attribute 'cursor'
Dec 20 '19 #1
0 1580

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Alexander Vlasenko | last post by:
Please CC me, I am not subscribed. An imaginary SQL statement INSERT INTO table FETCH ... FROM cursor; looks almost the same as currently available INSERT INTO table SELECT ...; I tried it...
2
by: db2group88 | last post by:
hi, we install db2 udb v8.1 on windows 64bit, in our application, we have sql execute "create table .... not logged initially", but from the operating system event viewer showing error stating that...
1
by: AndrewD | last post by:
when the following SELECT is executed via A cursor to SQL 2005 it works SELECT * FROM LCTRY WHERE LANGUAGE = 'EN' AND CTRY_CODE = :CTRY BUT SELECT * FROM LCTRY WHERE CTRY_CODE = :CTRY...
4
by: invy | last post by:
Hi, I'm experiencing a problem while declaring scroll cursor. I'm using Embeded SQL with C. my code is given below. #ifdef SQLSRVR_RDBMS EXEC SQL DECLARE CUR_DWNLD SCROLL CURSOR FOR SCURS;...
0
by: sunkesulachakradhar | last post by:
Hi, Our application is developed in VC++ back end is Oracle. We are running into a issue with Maximum Cursor Error after iterating through some work flow for about 40 times. with this...
0
by: selvazeal | last post by:
ID SON ACC 141 1 4511039999 141 1 131XXXXXXX 141 1 4411109999 141 1 5940029999 141 1 5940049999 141 1 4431009999 166 1 4511039999 166 1 131XXXXXXX 166 1 4411109999
1
by: sfayed | last post by:
Hello, Does anyone have a good solution to close cursors when using Oracle 9 with VB.NET. I have tried disposing of the command object, the data adapter and increasing the OPEN_CURSORS variable...
1
by: Dreea | last post by:
Hello all What is the appropriate syntax for declaring a cursor for a table name that is passed as a parameter to a procedure? I tried several combination and it doesn't seem to work. CREATE...
1
by: Amey Morye | last post by:
one System A is sending messages to System B in TLV format over MQ. outgoing table column of System A is CLOB Incoming table column of system B is LONG. When the messages which reach the MQ of...
1
by: manikandanc | last post by:
if i tying to insert the values in access table not showing any error but also not saving the values in table. plz,Help.
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.