41 lines
750 B
Python
41 lines
750 B
Python
import pyodbc
|
|
|
|
try:
|
|
connection = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=.;DATABASE=SampleDB;Trusted_Connection=yes')
|
|
|
|
cursor = connection.cursor()
|
|
|
|
sql_cmd = """
|
|
declare @out nvarchar(max)
|
|
exec dbo.usp_cus_details @cus_id = ?, @out = @out output;
|
|
"""
|
|
|
|
prm_id=3
|
|
|
|
cursor.execute(sql_cmd, prm_id)
|
|
|
|
print("[printing sp call]")
|
|
rows = cursor.fetchall()
|
|
|
|
while rows:
|
|
print(rows)
|
|
if cursor.nextset():
|
|
rows = cursor.fetchall()
|
|
else:
|
|
rows = None
|
|
|
|
print()
|
|
|
|
cursor.close()
|
|
connection.close()
|
|
|
|
except pyodbc.Error as ex:
|
|
print()
|
|
print("exception: ",ex)
|
|
cursor.close()
|
|
connection.close()
|
|
print()
|
|
exit()
|
|
|
|
print()
|