python 连接远程 sql server 数据库代码
时间: 2023-06-06 07:07:32 浏览: 320
python数据库(mysql)连接代码
以下是连接远程 sql server 数据库的 Python 代码示例:
```
import pyodbc
server = 'your_server_name'
database = 'your_database_name'
username = 'your_username'
password = 'your_password'
connection_string = 'DRIVER={ODBC Driver 17 for SQL Server};SERVER=' + server + ';DATABASE=' + database + ';UID=' + username + ';PWD=' + password
connection = pyodbc.connect(connection_string)
cursor = connection.cursor()
cursor.execute('SELECT * FROM your_table_name')
for row in cursor:
print(row)
```
阅读全文