我正在使用 MS Access 2003(没有其他可用)为快照样式数据库构建临时后端,这涉及将一些链接的 tabledef 添加到临时后端。该代码已经工作了大约 3 周,但截至今天下午早些时候,开始抛出 3356(即机器 Y 上的用户 X 已经以独占模式打开了数据库......)或 3045(大致,无法打开数据库在独占模式下),这取决于我是否已经在 Access 中建立了连接。
错误代码大致(略微修剪):
Private Sub AddTabledefToDb(dbC As DAO.Database, dbTarget As DAO.Database, strLinkedName As String)
Dim strPath As String, tdfLinked As DAO.TableDef
strPath = strGetPathFromConnect(tdfLinked.Connect)
Set tdfLinked = dbC.TableDefs(strLinkedName)
' With the lines below, error thrown is 3356; without 3045 '
Dim dbLinkedTableIn As DAO.Database
Set dbLinkedTableIn = Application.DBEngine.Workspaces(0).OpenDatabase(strPath, False, True, tdfLinked.Connect)
Dim tdfNew as DAO.TableDef
Set tdfNew = dbTarget.CreateTableDef(Attributes:=dbAttachedTable)
tdfNew.Name = tdfLinked.Name
tdfNew.SourceTableName = tdfLinked.SourceTableName
tdfNew.Connect = tdfLinked.Connect
dbTarget.TableDefs.Append tdfNew ' Throws 3045 without the lines above or 3356 with them '
' If needed... '
dbLinkedTableIn.Close
Set dbLinkedTableIn = Nothing
End Sub
我怀疑其原因可能与我打开包含我直接链接到的表的数据库时显示的消息有关,即它仅在只读模式下可用(我相当确定不是以前的情况)。但是,我不清楚为什么我的代码需要的不仅仅是只读访问权限,而且我无法弄清楚它为什么要尝试获取它(尤其是当我事先以只读模式显式打开数据库时)。
任何帮助将不胜感激。
谢谢