热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何通过.NET代码压缩和修复ACCESS2007数据库?-HowdoIcompactandrepairanACCESS2007databaseby.NETcode?

IneedtocompactandrepairanAccess2007.accdbdatabasefile.IknowthatJRO.JetEnginecandot

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.

我需要压缩和修复Access 2007 .accdb数据库文件。我知道JRO.JetEngine可以使用.mdb文件执行此操作,但我需要通过代码修复较新的版本2007格式。

Any suggestions?

有什么建议么?

EDIT:

编辑:

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.

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

This is driving me crazy.

这真让我抓狂。

5 个解决方案

#1


6  

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

似乎Office 12数据库引擎在任何地方都没有任何文档。

Not quite true. There is limited information available.

不完全正确。信息有限。

On MSDN, see:

在MSDN上,请参阅:

Access 2007 Developer Reference

Access 2007开发人员参考

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.

有一个用于Microsoft Jet复制对象(JRO)参考的分支,因此对于ACE,JRO(包含ADO classic的库之一)仍然是官方支持(并且AFAIK仍然可以工作)。 accdb格式。 CompactDatabase方法有两个参数,两个参数都是OLE DB连接字符串。因此,提供数据库密码应该与常规连接没有区别,例如使用Jet OLEDB:连接字符串中的数据库密码。请记住,对于accdb格式,您需要在连接字符串中包含Jet OLEDB:Engine Type = 5,例如

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

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.

对于它的价值(事实证明并不多),ACE引擎的有限文档可以在Access 2007 for Access 2007中找到。

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.

请记住,大多数Access数据库引擎都是在20世纪90年代开发的,当时专有格式风靡一时;我怀疑文档是出于商业原因而被压制而且知识遗失了。因此,目前可用的文档中存在许多漏洞,而且存在大量漏洞。通常,找出引擎如何工作的唯一方法是通过实际使用来发现它。存在的文档包含一些令人震惊的错误:今天我已经在SO上发布了几个示例,其中可能使用但虚构的功能(LIMIT to nn ROWS,CREATE TEMPORARY TABLE等)已在Access帮助中公布。买者自负。

#2


3  

I know this is an old thread, but this worked for me (for VB.Net). Hopefully it can help someone down the road:

我知道这是一个旧线程,但这对我有用(对于VB.Net)。希望它可以帮助有人在路上:

​Add a reference to "Microsoft Office 12.0 Access database engine Object Library"

添加对“Microsoft Office 12.0 Access数据库引擎对象库”的引用

Dim dbe As New Microsoft.Office.Interop.Access.Dao.DBEngine

dbe.CompactDatabase("C:\folder\database.accdb",  "C:\folder\database_New.accdb", , , ";pwd=")

http://www.tolchin.net/KB/Lists/Posts/Post.aspx?ID=9

http://www.tolchin.net/KB/Lists/Posts/Post.aspx?ID=9

#3


2  

Just an FYI regarding JRO, it does not support Access version 2007 or higher database files. While the CompactDatabase method in this library appears to function when using the ACE OLEDB Provider, it will in fact generate a 2002-2003 (Jet 4.0) database file.

仅仅是关于JRO的FYI,它不支持Access版本2007或更高版本的数据库文件。虽然此库中的CompactDatabase方法在使用ACE OLEDB Provider时似乎起作用,但它实际上会生成2002-2003(Jet 4.0)数据库文件。

BTW, an Engine Type = 5 is Jet 4.0, so that should be a dead giveaway as to version created.

BTW,引擎类型= 5是Jet 4.0,因此对于版本创建应该是一个死的赠品。

#4


2  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;
using System.Data;
using Microsoft.Office.Interop.Access.Dao;
protected void btnSubmitDenim_Click(object sender, EventArgs e)
{
    try
       {
string oldFileName = HttpContext.Current.Server.MapPath(@"~/App_Data/MyDatainAccess2010.accdb");
string newFileName = HttpContext.Current.Server.MapPath(@"~/App_Data/Temp.accdb");

   // Obtain a reference to the Access 2010 introp DBEngine formally known as JetEngine

    DBEngine engine = (DBEngine)HttpContext.Current.Server.CreateObject("Dao.DBEngine.120");


  // Compact the database (saves the compacted version to newFileName)

    engine.CompactDatabase(oldFileName, newFileName);


            // Delete the original database
            File.Delete(oldFileName);

            // Move (rename) the temporary compacted database to
            // the original filename
            File.Move(newFileName, oldFileName);

            // The operation was successful
            lblResult.Text = "Database Compact completed";
       }
       catch
       {
           // We encountered an error
           lblResult.Text = "Process Failed";

       }
    }

// Hope that helps
// Wasif

#5


1  

You don't need JRO. JRO should not even exist -- it is one of the ugly stepchildren of ADODB that came about because of Microsoft's misguided attempt to replace Access/Jet/ACE's native DAO with ADO, a non-native abstraction layer. JRO is there to provide support for Jet-specific functionality not available in ADODB.

你不需要JRO。 JRO甚至不应该存在 - 它是ADODB的丑陋继子之一,因为微软试图用ADO(非本地抽象层)取代Access / Jet / ACE的原生DAO。 JRO可以为ADODB中没有的Jet特定功能提供支持。

If you used DAO instead, you'd have all the functionality right there already, and it works for all formats supported by the version of Access you're using (since the DAO version is synchronized with your Access version, that is, when the db engine is enhanced, there's a new version of DAO to go with it).

如果您使用DAO,那么您已经具备了所有功能,它适用于您正在使用的Access版本所支持的所有格式(因为DAO版本与您的Access版本同步,也就是说,数据库引擎得到了增强,还有一个新版本的DAO可以使用它。

So, in A2007, you'd simply use the DAO compact methods (there's been no repair operation as a separate command since Access 2, and a repair happens only if the database engine determines during the compact that a repair is necessary). If you're working from outside Access, then you need to use the ACE-compatible version of DAO. If you do not have A2007 installed and have installed the ACE independently, you have that version of DAO installed along with it.

因此,在A2007中,您只需使用DAO紧凑方法(自Access 2以来,没有任何修复操作作为单独的命令,并且只有在数据库引擎在压缩期间确定需要修复时才会进行修复)。如果您在Access外部工作,则需要使用兼容ACE的DAO版本。如果您没有安装A2007并且已经独立安装了ACE,那么您将安装该版本的DAO。


推荐阅读
  • 本文详细介绍了SQL日志收缩的方法,包括截断日志和删除不需要的旧日志记录。通过备份日志和使用DBCC SHRINKFILE命令可以实现日志的收缩。同时,还介绍了截断日志的原理和注意事项,包括不能截断事务日志的活动部分和MinLSN的确定方法。通过本文的方法,可以有效减小逻辑日志的大小,提高数据库的性能。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 使用Ubuntu中的Python获取浏览器历史记录原文: ... [详细]
  • 本文介绍了Oracle数据库中tnsnames.ora文件的作用和配置方法。tnsnames.ora文件在数据库启动过程中会被读取,用于解析LOCAL_LISTENER,并且与侦听无关。文章还提供了配置LOCAL_LISTENER和1522端口的示例,并展示了listener.ora文件的内容。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 关于我们EMQ是一家全球领先的开源物联网基础设施软件供应商,服务新产业周期的IoT&5G、边缘计算与云计算市场,交付全球领先的开源物联网消息服务器和流处理数据 ... [详细]
  • ZSI.generate.Wsdl2PythonError: unsupported local simpleType restriction ... [详细]
  • 图解redis的持久化存储机制RDB和AOF的原理和优缺点
    本文通过图解的方式介绍了redis的持久化存储机制RDB和AOF的原理和优缺点。RDB是将redis内存中的数据保存为快照文件,恢复速度较快但不支持拉链式快照。AOF是将操作日志保存到磁盘,实时存储数据但恢复速度较慢。文章详细分析了两种机制的优缺点,帮助读者更好地理解redis的持久化存储策略。 ... [详细]
  • http:my.oschina.netleejun2005blog136820刚看到群里又有同学在说HTTP协议下的Get请求参数长度是有大小限制的,最大不能超过XX ... [详细]
  • XML介绍与使用的概述及标签规则
    本文介绍了XML的基本概念和用途,包括XML的可扩展性和标签的自定义特性。同时还详细解释了XML标签的规则,包括标签的尖括号和合法标识符的组成,标签必须成对出现的原则以及特殊标签的使用方法。通过本文的阅读,读者可以对XML的基本知识有一个全面的了解。 ... [详细]
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
  • 本文介绍了iOS数据库Sqlite的SQL语句分类和常见约束关键字。SQL语句分为DDL、DML和DQL三种类型,其中DDL语句用于定义、删除和修改数据表,关键字包括create、drop和alter。常见约束关键字包括if not exists、if exists、primary key、autoincrement、not null和default。此外,还介绍了常见的数据库数据类型,包括integer、text和real。 ... [详细]
  • Redis底层数据结构之压缩列表的介绍及实现原理
    本文介绍了Redis底层数据结构之压缩列表的概念、实现原理以及使用场景。压缩列表是Redis为了节约内存而开发的一种顺序数据结构,由特殊编码的连续内存块组成。文章详细解释了压缩列表的构成和各个属性的含义,以及如何通过指针来计算表尾节点的地址。压缩列表适用于列表键和哈希键中只包含少量小整数值和短字符串的情况。通过使用压缩列表,可以有效减少内存占用,提升Redis的性能。 ... [详细]
  • Whatsthedifferencebetweento_aandto_ary?to_a和to_ary有什么区别? ... [详细]
  • 本文介绍了响应式页面的概念和实现方式,包括针对不同终端制作特定页面和制作一个页面适应不同终端的显示。分析了两种实现方式的优缺点,提出了选择方案的建议。同时,对于响应式页面的需求和背景进行了讨论,解释了为什么需要响应式页面。 ... [详细]
author-avatar
办事繁华_491
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有