访问“紧凑和维修";以编程方式 [英] Access "Compact and Repair" programmatically

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

问题描述

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

解决方案

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

多年来,我一直在使用JRO方法从VB.net压缩/修复我的Access 2000数据库.每到一个蓝月亮,我都会有一个客户端设法损坏数据库(通常是通过网络连接到数据库,并且它们遭受意外的网络中断).只要数据库没有损坏,JRO(以我的经验)就可以正常工作.我永远无法弄清楚为什么使用Access应用程序可以修复数据库,但是当使用MY应用程序(使用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 As New dao.DBEngine
dao.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天全站免登陆