0

I was hoping someone could help me with a certain issue...

Here's a sample of a funtion I have:

from pyodbc import connect
from pandas import read_sql

conn = connect('Driver={SQL Server};SERVER=Server_Name;DATABASE=Database_Name;Trusted_Connection=Yes', autocommit=True)
current_date = datetime.now().date().strftime("%Y-%m-%d")
query1 = f"exec [dbo].[Stored_Precedure_Name] @param1 = 1, @param2= N'{current_date}'"
df = read_sql(query1, conn)

The problem is that this reqest takes about 7 minutes to load. But if I execute it in SSMS, it only takes a few seconds to load.

I have no idea why it takes Python so long to load compared to SSMS. Does anybody know why is it so? Any ideas appreciated.

  • I suspect that you are being misled by the SSMS user interface. When we execute a query, SSMS starts populating the results grid as it continues to retrieve rows in the background. As you can see in [this screenshot](https://i.stack.imgur.com/nnnTs.png), the grid has been populated with the first ~15 rows (that we can see) but the status bar still says "Executing query..." because it hasn't received all of the rows yet. The status bar changes to "Query executed successfully." when the process is actually complete. – Gord Thompson Mar 15 '22 at 14:11
  • Thanks for your reply. I'm aware of how SSMS interface works, so that's clearly not the case – Ghost In The Shell Mar 16 '22 at 12:25
  • How long does it take if you run the SP from `sqlcmd`? – Gord Thompson Mar 16 '22 at 13:29

0 Answers0