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