473,387 Members | 1,512 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,387 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 1578

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.
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.