用python查询MSSQL时比较好的异常处理
确保发生异常时记录集被关闭
1 #-*- coding: utf-8
2 # python 3.0 required
3 """确保发生异常时记录集被关闭"""
4
5 from win32com.client import Dispatch
6 try:
7 rs=Dispatch("ADODB.Recordset")
8 rs.ActiveConnection="PROVIDER=SQLOLEDB;"
9 rs.Source="select * from ATable"
10 rs.Open()
11 while not rs.EOF:
12 #DO SOME WORKS
13 rs.MoveNext()
14 except Exception as e:
15 print(e)
16 finally:
17 if 'rs' in dir():
18 if rs.State==1:
19 rs.Close()
20 del rs
以上是 用python查询MSSQL时比较好的异常处理 的全部内容, 来源链接: utcz.com/z/386998.html