vb.net - 访问 2007 紧凑型数据库
问题描述
对不起我的英语,我从意大利写信。我在 VB Net 的业务数据管理程序中使用 Access 2007 DB。众所周知,Access DB 在使用过程中会扩展,因此我需要在程序关闭时压缩它们。我以这种方式执行压缩
Dim MioEngine As New Microsoft.Office.Interop.Access.Dao.DBEngine
MioEngine.CompactDatabase(myAccesDB, newAccessDB,)
Application.DoEvents()
但通常而不是在网络上的所有 PC 上,压缩不会完成并给我以下错误消息: 进程无法访问“C:\myAccesDB.accdb”文件,因为它正在被另一个进程使用 深入分析什么发生时,我看到发生错误时,.laccdb 文件在压缩时没有关闭。除了我用来安全压实的方法之外,还有其他方法吗?我指定我们网络中的所有 PC 都是 Windows 10 专业版并且全部更新;当 Windows 10 处于起步阶段时,我没有收到此错误。
解决方案
由于我的评论还不够,这里有一个答案:
这个想法是在.laccdb
尝试压缩数据库之前尝试打开文件。你可以这样做:
Dim file as System.IO.FileInfo = New System.IO.FileInfo("c:\myAccesDB.laccdb")
Dim stream As FileStream = Nothing
Try
stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None)
stream.Close()
'if stream is successfully closed, file is not in use and database can be compacted
MioEngine.CompactDatabase(myAccesDB, newAccessDB,)
Catch ex As Exception
'show some message to user that file is in use so it can try again
End Try
我很久以前就使用过 VB 和 Access,所以这只是你应该采取的方向。
推荐阅读
- symfony - Symfony 身份验证不起作用
- php - CalendarView 只获取今天的事件
- docker - Gitlab CE 抛出错误,Web IDE 挂在 nginx 反向 pxy (jwilder) 后面
- python - Boto3 不将快照复制到其他区域,其他选项?
- python - 带有滚动面具的熊猫滚动平均值/不包括条目
- javascript - 向dom添加元素不起作用
- javascript - jQuery - 在父行下方填充子表
- git - GIT 只添加了两行“jquery-3.3.1.min.js”文件;它不会添加/提交整个文件
- android - 我的活动方面发生了变化
- java - 我正在使用两个 for 循环并想要 25 个“i”(内循环)值 wrt “j”或 X[] 值。但它显示了一些不同的东西。请帮助我