Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3.x: Error on pyodbc sql server connection "no attribute 'execute"

I keep getting the error: "'builtin_function_or_method' object has no attribute 'execute'" I originally thought the complaint was on the table value function in SQL Server, however, I see that the message points to "execute", so I don't think refcur has execute defined. Here's what my connection string looks like:

    conn = pyodbc.connect("Driver={SQL Server};"
                      "Server=myserver;"
                      "Database=mydatabase;"
                      "Trusted_Connection=yes;"
                      "autocommit=True;")

    refcur = conn.cursor
    sql = "exec myschema.mystoredproc @TVPobject=?"
    refcur.execute(sql,this_object)

I've attached the image to show what I see in intellisense for what's available. Does anyone know why this is happening?

enter image description here

like image 693
plditallo Avatar asked Nov 29 '25 16:11

plditallo


1 Answers

you aren't calling cursor, you're just returning a reference to that member function and storing it in refcur. In order to call it (and actually create a cursor), you need to add parenthesis:

refcur = conn.cursor()
# Here -------------^
like image 168
Mureinik Avatar answered Dec 02 '25 05:12

Mureinik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!