访问“压缩和修复"以编程方式 [英] Access "Compact and Repair" programmatically

查看:33
本文介绍了访问“压缩和修复"以编程方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以以某种方式(使用 ADOX、使用 OleDbConnection 等)以编程方式压缩和修复"Access 数据库?

解决方案

我没有足够的代表来回复以前的答案",但我想提供一些可能对其他人有帮助的信息OP 的问题.

我多年来一直使用 JRO 方法来压缩/修复来自 VB.net 的 Access 2000 数据库.每隔一段时间,我都会有一个客户端设法破坏数据库(通常是在通过网络连接到数据库时遇到意外的网络中断).JRO(以我的经验)工作正常,只要数据库没有损坏.如果我使用 Access 应用程序来修复数据库,我永远无法弄清楚为什么可以修复数据库,但是当使用我的应用程序(使用 JRO)时,压缩/修复总是会失败(数据库采用无法识别的格式).

因此,在一小时前遇到这个线程后,我将 DAO 的引用放入我的应用程序并尝试了它修复损坏数据库的能力,因为我今天有一个客户端损坏了他们的数据库(第三次发生在大约 8 年).猜猜看,当 JRO 失败时,DAO 能够修复数据库!

好的,这就是我对 JRO 与 DAO 的体验.希望能帮助到你.这是使用 CompactDatabase 的一段示例代码 来自 DAO:

Dim dbCorrupt As String = "c:CorruptedDB.mdb"Dim dbRepaired As String = Path.Combine(Path.GetDirectoryName(dbPath), Path.GetFileNameWithoutExtension(dbPath) & "_Repaired.mdb")Dim dao 作为新的 dao.DBEnginedao.CompactDatabase(dbCorrupt, dbRepaired)

Is it possible to "compact and repair" an Access database programmatically somehow (using ADOX, using OleDbConnection etc.)?

解决方案

I don't have enough rep to reply to a previous "answer", but I wanted to provide some info that might be helpful to someone else in regards to the OP's question.

I have been using the JRO method for years to compact/repair my Access 2000 databases from VB.net. Every once in a blue moon, I have a client that has managed to corrupt a database (usually when connected to the database over a network and they suffer an unexpected network interruption). JRO (in my experience) works fine, as long as the database IS NOT CORRUPTED. I never could figure out why the database COULD be repaired if I used the Access application to do it, but when using MY application (which uses JRO), the compact/repair would always fail (database is in an unrecognized format).

So, after coming across this thread just an hour ago, I dropped a reference to DAO into my app and tried out its ability to repair a corrupted database as I just today had a client corrupt their database (third time its happened in about 8 years). Guess what, DAO was able to repair the database when JRO failed!

OK, so that is my experience with JRO vs. DAO. Hope it helps. Here is a piece of sample code for using CompactDatabase from DAO:

Dim dbCorrupt As String = "c:CorruptedDB.mdb"
Dim dbRepaired As String = Path.Combine(Path.GetDirectoryName(dbPath), Path.GetFileNameWithoutExtension(dbPath) & "_Repaired.mdb")

Dim dao As New dao.DBEngine
dao.CompactDatabase(dbCorrupt, dbRepaired)

这篇关于访问“压缩和修复"以编程方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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