压缩access数据库
生活随笔
收集整理的這篇文章主要介紹了
压缩access数据库
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
遇到一個問題,使用的是accesss數據庫,在加載數據庫中的信息的時候,速度特別慢,有時候一次查詢最終會卡15秒左右,然后才能得到結果,跟蹤發現卡的地方在SQLExecDirect中,已經是odbc api了。打開數據庫看也沒發現啥問題,后來點了access上邊的 “壓縮和修復數據庫”工具,數據庫從原來的 8M 瞬間變成了 800k ,使用壓縮后的數據庫時速度就特別快了,不知道是不是access數據庫的啥毛病,記錄下壓縮用到的代碼:
關鍵代碼:
壓縮之后替換原來的文件,完整代碼:
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"總結
以上是生活随笔為你收集整理的压缩access数据库的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: access连接mysql很慢_怎么解决
- 下一篇: Netty高级进阶之基于Netty的We