发布时间:2019-08-08 07:46:20编辑:auto阅读(1640)
# coding=gbk
import sys
import pymssql
#尝试数据库连接
try:
conn = pymssql.connect(host="192.168.1.43",user="sa",password="sa01!", database="master")
except pymssql.OperationalError, msg:
print "error: Could not Connection SQL Server!please check your dblink configure!"
sys.exit()
else:
cur = conn.cursor()
#查询数据库
query="select name, database_id, recovery_model_desc from sys.databases"
cur.execute(query)
conn.commit
rows = cur.fetchall()
print (' ')
print ('-----结果返回中------- ')
print (' ')
for (name,database_id,recovery_model_desc) in rows:
database_id=bytes(database_id) #将int转换转换为字符串类型
print ('数据库名:' +str(name)+';')
print ( '数据库id:' +database_id )
print ( '数据库恢复模式:'+str(recovery_model_desc) )
print (' ')
print ('-----以上是所有结果!------- ')
#关闭连接,释放资源
cur.close()
conn.close()
上一篇: Python_Nginx
下一篇: python简单socket
47496
45799
36797
34327
28970
25600
24445
19613
19113
17635
5469°
6051°
5573°
5640°
6575°
5378°
5380°
5887°
5858°
7174°