问题
If I use SQL Management Studio. When I create/drop tables, or do any updates, I can see messages like:
"Command(s) completed successfully."
"Cannot drop the table 'my_table', because it does not exist or you do not have permission."
But if I use python to execute the same query:
connection = pypyodbc.connect('my connect options...')
cursor = connection.cursor()
my_result = cursor.execute('my create/drop table sql...')
my_result = connection.commit()
I can see nothing from "my_result", "cursor" or "connection". Is the message generated by sql management studio? If not, and it is a sql server engine returned message, how to get this message?
回答1:
The messages displayed in the messages tab in SSMS are passed as InfoMessage events on the connection. Here's the C# API doco
https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.infomessage.aspx
I'm not a python user so can't really help beyond pointing you at the documentation.
Edit: This answer might help you Getting SQL Server messages using ADO and win32com
来源:https://stackoverflow.com/questions/37734835/how-to-get-sql-server-returned-message