使用pyodbc库,可以使用以下代码判断sql server是否启动:
import pyodbc
try:
conn = pyodbc.connect('DRIVER={SQL Server};SERVER=<server>;DATABASE=<database>;UID=<username>;PWD=<password>')
print('SQL Server is up and running')
except:
print('SQL Server is not running')
使用pyodbc库,可以使用以下代码判断sql server是否启动:
import pyodbc
try:
conn = pyodbc.connect('DRIVER={SQL Server};SERVER=<server>;DATABASE=<database>;UID=<username>;PWD=<password>')
print('SQL Server is up and running')
except:
print('SQL Server is not running')