如何通過python連線sqlserver

2021-10-09 02:00:16 字數 527 閱讀 1460

# *.* coding=utf-8 *.*

import pymssql

server = "127.0.0.1"

# 連線伺服器位址

user = 'sqluser'

# 連線帳號

password = "password"

# 連線密碼

with pymssql.connect(server,user,password,'yourdatabase',charset="utf-8") as conn:

with conn.cursor(as_dict=true) as cursor: # 資料存放到字典中

cursor.execute('select * from accesslevel_table where recordid=1')

for row in cursor:

print("id=%d" % (row['recordid']))

通過以上可以把資料庫的id列印出來,能列印出來就說明連線成功了

通過python連線Oracle

一 安裝cx oracle pip install cx oracle即可 二 安裝instantclient windows方式 2.環境配置 import os os.environ nls lang simplified chinese china.utf8 os.environ tns ad...

Python通過ssh連線MySQL

機器a 通過機器b 登入機器c的mysql import pymysql from sshtunnel import sshtunnelforwarder server sshtunnelforwarder ssh address or host 機器b的ip 22 指定ssh登入的跳轉機的addr...

MFC通過ADO連線 SQL 2005

1 新建乙個類,型別為generic class,名稱為cdatabase 2 新增匯入檔案 import c program files common files system ado msado15.dll no namespace rename eof adoeof rename bof ad...