如何使用 adodbapi 正确查询 sql ce 4.0 数据库文件? [英] How do i correctly query a sql ce 4.0 database file using adodbapi?

查看:33
本文介绍了如何使用 adodbapi 正确查询 sql ce 4.0 数据库文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下方法:

def open(self, filename):
    if not os.path.exists(filename):
        raise IOError("Cannot find Game Database file {0}").__format__(filename)

    connstr = "Provider=Microsoft.SQLSERVER.CE.OLEDB.4.0; 
               Data Source={0};".format(filename)
    conn = adodbapi.connect(connstr)
    curs = conn.cursor()
    query = "Select * from Patient;"
    curs.execute(query)
    results = curs.fetchall()
    for r in results:
        print r

运行时,curs.execute(query) 会出现以下错误:

When this runs, the following error is rased on curs.execute(query):

(<class 'adodbapi.adodbapi.DatabaseError'>, u"(-2147352567, 'Exception occurred.', (0, u'Microsoft Cursor Engine', u'Multiple-step operation generated errors. Check each status value.', None, 0, -2147217887), None)\nCommand:\nSelect * from Patient;\nParameters:\n[]")

我可以在 compactView 中成功运行这个确切的查询.

I can run this exact query in compactView successfully.

我没有看到什么明显的语法糖?(运行:win7 pro x64、python 2.7.x、pywin32 和 adodbapi 安装成功.连接字符串似乎有效——我可以连接并获取光标就好了)

What obvious syntactic sugar am i not seeing? ( running: win7 pro x64, python 2.7.x, pywin32 and adodbapi installed successfully. The connection string seems to work -- i can connect and get a cursor just fine)

推荐答案

使用 adodbapi-2.6.0.7 我使用以下方法解决了这个问题:

Using adodbapi-2.6.0.7 I solved this using the following:

connection.connector.CursorLocation = 2

例如:

import adodbapi

file = r'FILEPATH'
connection_string = (
    'Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5; Data Source={};'.format(file))
print(connection_string)
connection = adodbapi.connect(connection_string)
connection.connector.CursorLocation = 2
connection.get_table_names()

这篇关于如何使用 adodbapi 正确查询 sql ce 4.0 数据库文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆