【问题标题】:Access 2010 Query Execution CrashAccess 2010 查询执行崩溃
【发布时间】:2019-01-10 22:16:00
【问题描述】:

在 Windows 10 和 MS Access 2010 中,我正在运行一个 vba 函数,该函数执行 SQL 查询,从链接到 Outlook 的链接表中提取记录。 查询如下所示:

select * from  where LinkedTable.Field1 like '*string1*' and (LinkedTable.Field2 like 'string2*' OR LinkedTable.Field2 like 'string3*' OR LinkedTable.Field2 like 'string4*' OR LinkedTable.Field2 like 'string5*' OR LinkedTable.Field2 like 'string6*' OR LinkedTable.Field2 like string7*')

在执行查询之前,我正在刷新表的链接。

运行该函数时访问崩溃。调试导致确定执行查询的点是 Access 崩溃时:Set rs2 = db.OpenRecordset(strQ)

代码如下:

    Sub xyz()
    Dim db As DAO.Database
    Dim rs2 As DAO.Recordset 'this the sql query table
    dim rs1 as DAO.Recordset
set rs1=db.openrecordset("anothertable")
rs1.movefirst
do while not rs1.eof 

    strQ ="select * from  LinkedTable where LinkedTable.Field1 like '*string1*' and (LinkedTable.Field2 like 'string2*' OR LinkedTable.Field2 like 'string3*' OR LinkedTable.Field2 like 'string4*' OR LinkedTable.Field2 like 'string5*' OR LinkedTable.Field2 like 'string6*' OR LinkedTable.Field2 like string7*')"

    db.TableDefs(LinkedTable).RefreshLink
    Set rs2 = db.OpenRecordset(strQ)
    .

rs2.close
set rs2=nothing
rs1.movenext
loop
    .
    .
    En

d 子

我注意到每次执行语句时内存使用量都会增加 设置 rs2 = db.OpenRecordset(strQ)

即使我正在清理,也会执行。清理后不释放。此语句会导致什么潜在的内存泄漏?

谢谢。

【问题讨论】:

    标签: database ms-access crash sql-like linked-tables


    【解决方案1】:

    问题可能是您的 SQL 语句被“智能引号”或 Unicode 字符 0x201C & 0x201D 括起来:

    ”select * from ... string7*')”
    

    与标准双引号相反,它是 Unicode/ASCII 字符 0x0022:

    "select * from ... string7*')"
    

    您还缺少select 查询的数据源:

    select * from ??? where ...
    

    【讨论】:

    • 实际上,引号和 From 不是问题,因为我在代码中正确设置了它们。我在摘录中错过了他们。该功能有时会起作用,但有时会崩溃。
    猜你喜欢
    • 2011-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多