3

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

1 Answer 1

4

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 -------------^
Sign up to request clarification or add additional context in comments.

1 Comment

Now this has to be the DUMBEST thing I've ever posted--but I was spending way too much time on it. I didn't even notice the missing parenthesis. I'll leave this posted. I'm sure I am not the only one that has spent (or will spend) time chasing this error for this very reason! :) @Mureinik, thanks so much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.