CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  数据库

请问如何用程序控制压缩Access2000数据库?

楼主Xsean()2002-01-17 10:50:35 在 VC/MFC / 数据库 提问

就是相当于执行access菜单栏里的“修复和压缩数据库”的功能 问题点数:20、回复次数:12Top

1 楼jiangsheng(蒋晟.Net[MVP])回复于 2002-01-17 11:06:57 得分 0

CDaoWorkspace::CompactDatabase  
  static   void   PASCAL   CompactDatabase(   LPCTSTR   lpszSrcName,   LPCTSTR   lpszDestName,   LPCTSTR   lpszLocale   =   dbLangGeneral,   int   nOptions   =   0   );  
  throw(   CDaoException,   CMemoryException   );  
   
  static   void   PASCAL   CompactDatabase(   LPCTSTR   lpszSrcName,   LPCTSTR   lpszDestName,   LPCTSTR   lpszLocale,   int   nOptions,   LPCTSTR   lpszPassword   );  
  throw(   CDaoException,   CMemoryException   );  
   
  Parameters  
   
  lpszSrcName  
   
  The   name   of   an   existing,   closed   database.   It   can   be   a   full   path   and   filename,   such   as   “C:\\MYDB.MDB”.   If   the   filename   has   an   extension,   you   must   specify   it.   If   your   network   supports   the   uniform   naming   convention   (UNC),   you   can   also   specify   a   network   path,   such   as   “\\\\MYSERVER\\MYSHARE\\MYDIR\\MYDB.MDB”.   (Double   backslashes   are   required   in   the   path   strings   because   “\”   is   the   C++   escape   character.)  
   
  lpszDestName  
   
  The   full   path   of   the   compacted   database   that   you   are   creating.   You   can   also   specify   a   network   path   as   with   lpszSrcName.   You   cannot   use   the   lpszDestName   argument   to   specify   the   same   database   file   as   lpszSrcName.  
   
  lpszPassword  
   
  A   password,   used   when   you   want   to   compact   a   password-protected   database.   Note   that   if   you   use   the   version   of   CompactDatabase   that   takes   a   password,   you   must   supply   all   parameters.   Also,   because   this   is   a   connect   parameter,   it   requires   special   formatting,   as   follows:   ;PWD=lpszPassword.   For   example:   ;PWD=“Happy”.   (The   leading   semicolon   is   required.)  
   
  lpszLocale  
   
  A   string   expression   used   to   specify   collating   order   for   creating   lpszDestName.   If   you   omit   this   argument   by   accepting   the   default   value   of   dbLangGeneral   (see   below),   the   locale   of   the   new   database   is   the   same   as   that   of   the   old   database.   Possible   values   are:    
   
  dbLangGeneral       English,   German,   French,   Portuguese,   Italian,   and   Modern   Spanish  
   
   
  dbLangArabic       Arabic  
   
   
  dbLangCyrillic       Russian  
   
   
  dbLangCzech       Czech  
   
   
  dbLangDutch       Dutch  
   
   
  dbLangGreek       Greek  
   
   
  dbLangHebrew       Hebrew  
   
   
  dbLangHungarian       Hungarian  
   
   
  dbLangIcelandic       Icelandic  
   
   
  dbLangNordic       Nordic   languages   (Microsoft   Jet   database   engine   version   1.0   only)  
   
   
  dbLangNorwdan       Norwegian   and   Danish  
   
   
  dbLangPolish       Polish  
   
   
  dbLangSpanish       Traditional   Spanish  
   
   
  dbLangSwedfin       Swedish   and   Finnish  
   
   
  dbLangTurkish       Turkish    
  nOptions  
   
  Indicates   one   or   more   options   for   the   target   database,   lpszDestName.   If   you   omit   this   argument   by   accepting   the   default   value,   the   lpszDestName   will   have   the   same   encryption   and   the   same   version   as   lpszSrcName.   You   can   combine   the   dbEncrypt   or   dbDecrypt   option   with   one   of   the   version   options   using   the   bitwise-OR   operator.   Possible   values,   which   specify   a   database   format,   not   a   database   engine   version,   are:    
   
  dbEncrypt       Encrypt   the   database   while   compacting.  
   
   
  dbDecrypt       Decrypt   the   database   while   compacting.  
   
   
  dbVersion10       Create   a   database   that   uses   the   Microsoft   Jet   database   engine   version   1.0   while   compacting.  
   
   
  dbVersion11       Create   a   database   that   uses   the   Microsoft   Jet   database   engine   version   1.1   while   compacting.  
   
   
  dbVersion20       Create   a   database   that   uses   the   Microsoft   Jet   database   engine   version   2.0   while   compacting.  
   
   
  dbVersion30       Create   a   database   that   uses   the   Microsoft   Jet   database   engine   version   3.0   while   compacting.  
  You   can   use   dbEncrypt   or   dbDecrypt   in   the   options   argument   to   specify   whether   to   encrypt   or   to   decrypt   the   database   as   it   is   compacted.   If   you   omit   an   encryption   constant   or   if   you   include   both   dbDecrypt   and   dbEncrypt,   lpszDestName   will   have   the   same   encryption   as   lpszSrcName.   You   can   use   one   of   the   version   constants   in   the   options   argument   to   specify   the   version   of   the   data   format   for   the   compacted   database.   This   constant   affects   only   the   version   of   the   data   format   of   lpszDestName.   You   can   specify   only   one   version   constant.   If   you   omit   a   version   constant,   lpszDestName   will   have   the   same   version   as   lpszSrcName.   You   can   compact   lpszDestName   only   to   a   version   that   is   the   same   or   later   than   that   of   lpszSrcName.  
   
  CAUTION       If   a   database   is   not   encrypted,   it   is   possible,   even   if   you   implement   user/password   security,   to   directly   read   the   binary   disk   file   that   constitutes   the   database.  
   
  Remarks  
   
  Call   this   member   function   to   compact   a   specified   Microsoft   Jet   (.MDB)   database.   As   you   change   data   in   a   database,   the   database   file   can   become   fragmented   and   use   more   disk   space   than   necessary.   Periodically,   you   should   compact   your   database   to   defragment   the   database   file.   The   compacted   database   is   usually   smaller.   You   can   also   choose   to   change   the   collating   order,   the   encryption,   or   the   version   of   the   data   format   while   you   copy   and   compact   the   database.    
   
  !   WARNING       The   CompactDatabase   member   function   will   not   correctly   convert   a   complete   Microsoft   Access   database   from   one   version   to   another.   Only   the   data   format   is   converted.   Microsoft   Access-defined   objects,   such   as   forms   and   reports,   are   not   converted.   However,   the   data   is   correctly   converted.  
   
  Tip       You   can   also   use   CompactDatabase   to   copy   a   database   file.  
   
  For   more   information   about   workspaces,   see   the   articleDAO   Workspace   in   Visual   C++   Programmer's   Guide.   For   more   information   about   compacting   databases,   see   the   topic   "CompactDatabase   Method"   in   DAO   Help.  
   
  CDaoWorkspace   Overview   |     Class   Members   |     Hierarchy   Chart  
   
  See   Also       CDaoWorkspace::RepairDatabase  
   
   
  --------------------------------------------------------------------------------  
  Send   feedback   to   MSDN.Look   here   for   MSDN   Online   resources.   Top

2 楼Xsean()回复于 2002-01-17 11:19:02 得分 0

蒋晟:我没用DAO,我用的ADO,jet4.0引擎,不能用DAO的函数吧Top

3 楼jiangsheng(蒋晟.Net[MVP])回复于 2002-01-17 11:23:34 得分 0

jet4.0里面用修复数据库那个函数就可以了Top

4 楼Xsean()回复于 2002-01-17 13:06:32 得分 0

老蒋,找不到这个函数!不是俺不努力,只是......Top

5 楼jiangsheng(蒋晟.Net[MVP])回复于 2002-01-17 13:38:22 得分 0

……  
  没有repair开头的?Top

6 楼Xsean()回复于 2002-01-17 15:02:34 得分 0

只有几个数学、日期之类的函数。以下是我在其他论坛找的一篇贴子,是VB的解决方法,可我在VC下找不到这个东东.:  
   
  VB的ADO不能提供这种功能,但可以使用vb提供的Microsoft   Jet   and   Replication来压缩数据库  
  在引用中选中Microsoft   Jet   and   Replication,然后应用如下代码  
  Dim   j   As   New   JRO.JetEngine  
  j.CompactDatabase   "provider=Microsoft.Jet.OLEDB.4.0;data   source=e:\old.mdb",   "provider=Microsoft.Jet.OLEDB.4.0;data   source=e:\new.mdb;jet   oledb:encrypt   database=true"  
  然后删除old.mdb,重命名new.mdb为old.mdb即可   .Top

7 楼Xsean()回复于 2002-01-17 15:27:00 得分 0

jiangsheng(蒋晟) 快来呀Top

8 楼jiangsheng(蒋晟.Net[MVP])回复于 2002-01-17 15:40:10 得分 20

#import   "C:\PROGRAM   FILES\COMMON   FILES\System\ado\MSJRO.DLL"   no_namespace      
   
   
   
  Add   the   following   (specifying   your   own   source   and   destination   database   paths)   to   the   .cpp   file   where   you   want   to   compact   the   database:    
   
  ...  
  try  
  {  
          IJetEnginePtr   jet(__uuidof(JetEngine));  
          jet->CompactDatabase("Provider=Microsoft.Jet.OLEDB.4.0;Data   Source=d:\\nwind2.mdb",   "Provider=Microsoft.Jet.OLEDB.4.0;Data   Source=d:\\abbc.mdb;Jet   OLEDB:Engine   Type=4");  
  }  
  catch(_com_error   &e)    
  {                
                          ::MessageBox(NULL,   (LPCTSTR)e.Description(   ),   "",   MB_OK)   ;          
  }    
   
   
   
  NOTE:   The   Jet   OLEDB:Engine   Type=4   is   only   for   Jet   3.x   format   MDB   files.   If   this   value   is   left   out,   the   database   is   automatically   upgraded   to   the   4.0   version   (Jet   OLEDB:Engine   Type=5).   See   the   following   table   for   appropriate   values   for   Jet   OLEDB:Engine   Type:    
  Jet   OLEDB:Engine   Type   Jet   x.x   Format   MDB   Files    
  1   JET10    
  2   JET11    
  3   JET2X    
  4   JET3X    
  5   JET4X    
   
     
   
   
  Top

9 楼Xsean()回复于 2002-01-17 16:57:49 得分 0

老蒋,我服你了,真高手也!我在MSDN上怎么找不到呢?是不是2CD的没有这些内容啊?  
  另外还有个问题请教,我原来只加了msado15.dll,没有用MSJRO.DLL,可是打开数据时用MyDB->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data   Source=my.mdb","","",adModeUnknown);也没问题啊,那么这个jet   4.0引擎是哪里提供的呢?  
  还有MSJRO.DLL是随access还是随windows发布的?我如果要打包安装到win98下运行要不要把这些dll一起打包?  
   
  Top

10 楼Xsean()回复于 2002-01-17 19:51:19 得分 0

upupTop

11 楼jiangsheng(蒋晟.Net[MVP])回复于 2002-01-17 20:05:52 得分 0

www.microsoft.com/dataTop

12 楼snake1122(surfer)回复于 2002-01-18 10:48:09 得分 0

来看高手!Top

相关问题

  • (急!!)请问如何用 程序控制 备份SQL 数据库
  • 请问如何用vb程序控制SQL server进行备份数据库?
  • 请问如何用vb程序控制SQL server进行数据库的restore
  • 怎样用程序控制备份和恢复pocketpc的数据库?100分恭侯
  • Access数据库文件的压缩
  • access数据库压缩问题
  • ACCESS 数据库的压缩问题
  • 如何压缩ACCESS数据库
  • 如何压缩Access数据库
  • 压缩ACCESS数据库中的问题

关键词

  • 数据库
  • source
  • access
  • database
  • vb
  • microsoft
  • dll
  • jet
  • compactdatabase
  • mdb

得分解答快速导航

  • 帖主:Xsean
  • jiangsheng

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo