如何通过.NET代码压缩和修复ACCESS 2007数据库? [英] How do I compact and repair an ACCESS 2007 database by .NET code?

查看:501
本文介绍了如何通过.NET代码压缩和修复ACCESS 2007数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要压缩和修复Access 2007 .accdb数据库文件。我知道JRO.JetEngine可以用.mdb文件来做到这一点,但是我需要通过代码修复更新的2007版本。

I need to compact and repair an Access 2007 .accdb database file. I know that JRO.JetEngine can do this with .mdb files, but I need to repair the newer version 2007 format by code.

有什么建议吗?

编辑:

这里是事情:我发现我可以使用COM对象库Microsoft Office 12 Access数据库引擎对象库并使用DBEngine类并调用其CompactDatabse方法。
但是似乎没有一个地方为我提供数据库密码;似乎Office 12数据库引擎没有任何地方的任何文档。
我发现一些旧版本的CompactDatabase方法的文档,但是这些都不能帮助我。

Here is the thing: I found that I can use the COM object library "Microsoft Office 12 Access Database Engine Object Library" and use the DBEngine class and call its CompactDatabse method. But there doesn't seem to be a place for me to provide the database password; Seems like Office 12 Database Engine doesn't have any documentation anywhere. I found some documentation for older versions of CompactDatabase method but those don't help me at all.

这让我很疯狂。

推荐答案


似乎像Office 12数据库引擎
没有任何文档
。 / p>

Seems like Office 12 Database Engine doesn't have any documentation anywhere.

不完全正确。提供的信息有限。

Not quite true. There is limited information available.

在MSDN上,请参阅:

On MSDN, see:

Access 2007开发人员参考

Microsoft Jet复制对象(JRO)参考,因此JRO(包括ADO经典的库)仍然得到官方支持(AFAIK仍然工作)用于ACE accdb格式。 CompactDatabase方法使用两个参数,这两个参数都是OLE DB连接串。因此,提供数据库密码应与常规连接不同。在连接字符串中使用 Jet OLEDB:数据库密码。记住,对于accdb格式,您需要在连接字符串中包含 Jet OLEDB:Engine Type = 5

There is a branch for Microsoft Jet Replication Objects (JRO) Reference, so JRO (one of the libraries comprising ADO classic) is still officially supported (and AFAIK does still work) for ACE e.g. the accdb format. The CompactDatabase method takes two parameters, both of which is an OLE DB connection string. Therefore, supplying the database password should be no different from a regular connection e.g. using Jet OLEDB:Database Password in the connection string. Remember, for accdb format you need to include Jet OLEDB:Engine Type=5 in the connection string e.g.

Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=C:\MyDB.accdb;
Jet OLEDB:Database Password=MYPASSWORD;
Jet OLEDB:Engine Type=5

结果),ACE引擎的有限文档位于 Access 2007的Office帮助中

For what it's worth (not much, as it turns out), limited documentation for the ACE engine is found in the Office Help for Access 2007.

请记住,大多数Access数据库引擎是在20世纪90年代开发的,当专有格式是所有愤怒;我怀疑文档因为商业原因而被禁止,知识就丢失了。因此,在当前可用的文档中有很多漏洞,而那些大的漏洞。通常,找到发动机工作原理的唯一方法是通过实际使用来发现它。确实存在的文档包含一些令人沮丧的错误:已经今天我已经发布了一些示例SO,其中可能使用但虚构的功能(限制为nn ROWS CREATE TEMPORARY TABLE 等)已在Access帮助中发布。注意。

Bear in mind, most of the Access Database Engine was developed during the 1990s when proprietary formats were all the rage; I suspect documentation was suppressed for commercial reasons and the knowledge is simply lost. So there are many holes in the currently-available documentation, and large ones at that. Often, the only way of finding out how the engine works is to discover it through actual usage. The documentation that does exist contains some appalling errors: already today I've posted a couple of examples on SO where potentially use yet fictitious functionality (LIMIT TO nn ROWS, CREATE TEMPORARY TABLE, etc) has been advertised in the Access Help. Caveat emptor.

这篇关于如何通过.NET代码压缩和修复ACCESS 2007数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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