You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Golang调用ESENT.dll的JetAttachDatabase函数报错求助

Golang调用ESENT.dll读取ESEDB文件时的错误问题

问题背景

我尝试在Golang中通过ESENT.dll库打开并读取ESEDB文件,按照MSDN文档步骤:先创建ESE会话,依次调用JetInit、JetBeginSession、JetAttachDatabase完成文件挂载。但调用JetAttachDatabase时出现错误,初始错误码为4294965485。

初始代码

package main

import (
    "fmt"
    "os"
    "syscall"
    "unsafe"
)

var (
    esentDLL = syscall.NewLazyDLL("ESENT.dll")
    instance uintptr
    sesid uintptr
)

func main() {

    esedbFilePath, err := syscall.UTF16PtrFromString(".\\SRUDB.dat")
    if err != nil {
        fmt.Println(err.Error())
        os.Exit(1)
    } else {
        fmt.Println("Done")
    }
    initEseSession()
    attachEseDB(esedbFilePath)

}

func initEseSession() {

    JetInit := esentDLL.NewProc("JetInit")
    JetBeginSession := esentDLL.NewProc("JetBeginSession")

    fmt.Print("JetInit call... ")
    rInit, _, _ := JetInit.Call(
        uintptr(unsafe.Pointer(&instance)))

    if rInit != 0 {
        fmt.Println("Error", rInit)
    } else {
        fmt.Println("Done")
    }

    fmt.Print("JetBeginSession call... ")
    rBeginSession, _, _ := JetBeginSession.Call(
        instance,
        uintptr(unsafe.Pointer(&sesid)),
        0,
        0)

    if rBeginSession != 0 {
        fmt.Println("Error", rBeginSession)
    } else {
        fmt.Println("Done")
    }

}

func attachEseDB(esedbFilePath *uint16) {

    JetAttachDatabase := esentDLL.NewProc("JetAttachDatabase")

    fmt.Print("JetAttachDatabase call... ")
    rAttachDatabase, _, _ := JetAttachDatabase.Call(
        sesid,
        uintptr(unsafe.Pointer(&esedbFilePath)),
        0)

    if rAttachDatabase != 0 {
        fmt.Println("Error :", rAttachDatabase)
    } else {
        fmt.Println("Done")
    }

}

初始错误输出

JetInit call... Done
JetBeginSession call... Done
JetAttachDatabase call... Error : 4294965485

后续排查及更新后的错误

我将返回值转为int32获取了正确错误码,同时改用相对路径解决了“文件不存在”的问题,但调用JetAttachDatabase仍报错**-1032(文件无法访问,因为已被锁定或正在使用)**,后续相关操作也接连报错。测试多个干净导出的ESEDB文件均出现此问题,请求帮助解决。

更新后的错误输出:

Call JetCreateInstance...       Done    : Code 0 (The function succeeded)
Call JetInit...                 Done    : Code 0 (The function succeeded)
Call JetBeginSession...         Done    : Code 0 (The function succeeded)
Call JetAttachDatabase...       Error   : Code -1032 (The file cannot be accessed because the file is locked or in use)
Call JetOpenDatabase...         Error   : Code -1203 (There is no such database)
Call JetGetDatabaseInfo...      Error   : Code -1010 (There is an invalid database ID)
Call JetCloseDatabase...        Error   : Code -1010 (There is an invalid database ID)
Call JetDetachDatabase...       Error   : Code -1203 (There is no such database)
Call JetEndSession...           Done    : Code 0 (The function succeeded)
Call JetTerm...                 Done    : Code 0 (The function succeeded)

内容的提问来源于stack exchange,提问作者Ju Ctn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 07:33:12