首先import win32com.client #导入com相关的库
使用Python连接SQL Server 2005数据库时出现了以下问题:
rs = win32com.client.Dispatch(r'ADODB.Recordset')
rs.Open('[sometable]', conn, 1, 3)
有时候正常
有时候出现异常,提示:过程'sometable' 的请求失败,因为 'sometable' 是 表 对象。
按异常说明好像是把sometable当成过程来处理了,可这里是一个表名啊
网上搜索半天,未果
查看ADO帮助文档,发现recordset.Open 有5个参数
recordset.Open Source, ActiveConnection, CursorType, LockType, Options
其中第5个参数Options的说明如下:
Optional. A Long value that indicates how the provider should evaluate the Source argument if it represents something other than a Command object, or that the Recordset should be restored from a file where it was previously saved. Can be one or more CommandTypeEnum or ExecuteOptionEnum values, which can be combined with a bitwise OR operator.
大体就是说与Source参数有关,如何解释Source的意思
有如下几个定义
adCmdUnspecified -1 Does not spec