在pycharm中安装pyodbc插件,将servername和databasename修改为自己的数据库的名称,连接即可得到反馈
import pyodbc
server = 'your_server_name'
database = 'your_database_name'
driver = '{ODBC Driver 17 for SQL Server}' # or '{SQL Server}'
cnxn = pyodbc.connect(f'DRIVER={driver};SERVER={server};DATABASE={database};Trusted_Connection=yes;')
print(cnxn)