压缩access数据库
来源:互联网 发布:七天网络www7netcc查分 编辑:程序博客网 时间:2024/05/19 07:08
遇到一个问题,使用的是accesss数据库,在加载数据库中的信息的时候,速度特别慢,有时候一次查询最终会卡15秒左右,然后才能得到结果,跟踪发现卡的地方在SQLExecDirect中,已经是odbc api了。打开数据库看也没发现啥问题,后来点了access上边的 “压缩和修复数据库”工具,数据库从原来的 8M 瞬间变成了 800k ,使用压缩后的数据库时速度就特别快了,不知道是不是access数据库的啥毛病,记录下压缩用到的代码:
关键代码:
CDaoWorkspace dao; //将 Properties.mdb 压缩为 Properties_comp.mdb dao.CompactDatabase(g_CurrentPath + "Properties.mdb",g_CurrentPath + "Properties_comp.mdb");
压缩之后替换原来的文件,完整代码:
VOID CLoginPasswordDlg::CompactDatabase(){ try { CFileFind finder; if(finder.FindFile(g_CurrentPath + "Properties_comp.mdb")) { finder.Close(); DeleteFile(g_CurrentPath + "Properties_comp.mdb"); } if(finder.FindFile(g_CurrentPath + "Properties.mdb")) { finder.Close(); CFile file; if(file.Open(g_CurrentPath + "Properties.mdb",CFile::modeReadWrite)) { file.Close(); CDaoWorkspace dao; dao.CompactDatabase(g_CurrentPath + "Properties.mdb",g_CurrentPath + "Properties_comp.mdb"); } } } catch(...) { OutputDebugString("CompactDatabase exception."); } try { CFileFind finder; if(finder.FindFile(g_CurrentPath + "Properties.mdb") && finder.FindFile(g_CurrentPath + "Properties_comp.mdb")) { finder.Close(); if(!CopyFileA(g_CurrentPath + "Properties_comp.mdb",g_CurrentPath + "Properties.mdb",FALSE)) OutputDebugString("CopyFile failed."); DeleteFile(g_CurrentPath + "Properties_comp.mdb"); } } catch(...) { }}
需要包含头文件:
#include "afxdao.h"
阅读全文
0 0
- 怎样压缩access数据库
- 如何压缩Access数据库
- [原创] Access 数据库压缩
- C#压缩Access数据库
- VB 压缩Access数据库
- 如何压缩Access数据库
- VB 压缩Access数据库
- Delphi 压缩Access数据库
- 压缩修复Access数据库
- Delphi压缩access数据库
- 压缩access数据库
- 用Delphi 压缩Access数据库
- 压缩Access数据库的方法。
- 用Delphi压缩Access数据库
- VB.NET压缩ACCESS数据库
- Delphi下压缩Access数据库
- ASP压缩ACCESS数据库实用功能
- 压缩access数据库的方法。
- android 启动全屏+动画+判断是否是第一次登录
- kafka producer 发送消息
- 国内最安全的车,吉利副总裁让大家看车祸现场!
- 工作笔记--Git操作
- Mac版Android studio中使用lambda表达式设置jdk版本问题
- 压缩access数据库
- Spring+SpringMvc+Mybatis配置文件解读
- JS实现继承的几种方式
- Android解决自定义Dialog出现黑(白)框的问题
- 常用的正则大全
- spring mvc整合ireport
- java 中 += 和 =+运算的区别
- 剑指offer 合并链表
- Git-最简单的本地项目变成版本仓库,然后把内容推送到GitHub仓库