Difficulty executing SQL Server stored procedure programmatically using Python and ODBC

42 views Asked by At

I have an Amazon EC2 instance hosting a Microsoft SQL Server, and I'm attempting to execute a stored procedure programmatically using Python and ODBC. While I can successfully execute the stored procedure through SQL Server Management Studio, I encounter an issue when attempting to execute it using Python and ODBC.

    connection = pyodbc.connect(conn_str)
    print("Connected to DB")

    cursor = connection.cursor()
    cursor.execute(f"EXEC <schema>.<procedure-name>")

    cursor.fetchall()

I tried this, but it is returning None.

Additional Things:

  1. I have confirmed that the connection string (conn_str) is correct.
  2. The stored procedure executes successfully in SQL Server Management Studio.
  3. I have checked the permissions for the stored procedure and verified that the user has the necessary permissions to execute it.
  4. I'm using Python and pyodbc
0

There are 0 answers