程式 建立 壓縮Access資料庫並修改密碼演示

2021-03-31 08:56:31 字數 4447 閱讀 1576

* --------------------------------------------

* 程式: 建立、壓縮access資料庫並修改密碼演示

* 設計: 紅雨

* --------------------------------------------

local lcmdbfile, lcretustr

lcmdbfile = [c:/temp/testcreamdbfile.mdb]

lcpswd1 = [test1]

lcpswd2 = [test2]

lcpswd3 = [test3]

lcretustr = [建立、壓縮access資料庫並修改密碼演示:] + chr(13)

if createmdb( lcmdbfile, lcpswd1)

lcretustr = lcretustr + chr(13) + [1、建立資料庫成功         - 密碼: ] + lcpswd1

if ***pac***b( lcmdbfile, lcpswd1, lcpswd2 )

lcretustr = lcretustr + chr(13) + [2、壓縮並修改密碼成功     - 密碼: ] + lcpswd2

if changemdbpassword( lcmdbfile, lcpswd2, lcpswd3 )

lcretustr = lcretustr + chr(13) + [3、單獨修改資料庫密碼成功 - 密碼: ] + lcpswd3

else

lcretustr = lcretustr + chr(13) + [3、單獨修改資料庫密碼失敗]

endif

else

lcretustr = lcretustr + chr(13) + [2、壓縮並修改密碼失敗]

endif

else

lcretustr = lcretustr + chr(13) + [1、建立資料庫失敗]

endif

= messagebox( lcretustr, 0+64+0, [紅雨提示] )

return

* --------------------------------------------

function createmdb( tcmdbfile, tcpswdstr )

* 建立 access 資料庫檔案(.mdb)

local isok

isok = .f.

tcmdbfile = iif(type([tcmdbfile])=[c], tcmdbfile, )

tcpswdstr = iif(type([tcpswdstr])=[c], tcpswdstr, )

if file(tcmdbfile)

erase (tcmdbfile)

endif

if !file(tcmdbfile)

isok = .t.

local loengine, lcolderror, lccmdstrs

lcolderror = on([error])

on error isok = .f.

locatalog = createobject( [adox.catalog] )

lccmdstrs = [provider=microsoft.jet.oledb.4.0] ;

+ [;data source=] + tcmdbfile ;

+ [;jet oledb:database password=] + tcpswdstr

locatalog.create( lccmdstrs )

release locatalog

locatalog = null

on error &lcolderror.

endif

return isok and file(tcmdbfile)

endfunc

* --------------------------------------------

function ***pac***b ( tcmdbfile, tcoldpswd, t**ewpswd )

* 壓縮 access 資料庫並設定密碼

local isok

isok = .f.

tcmdbfile = iif(type([tcmdbfile])=[c], tcmdbfile, )

tcoldpswd = iif(type([tcoldpswd])=[c], tcoldpswd, )

t**ewpswd = iif(type([t**ewpswd])=[c], t**ewpswd, tcoldpswd)

if file( tcmdbfile )

isok = .t.

local loengine, lctmpfile, lcolderror, lc***poldstr, lc***pnewstr

lcolderror = on([error])

on error isok = .f.

lctmpfile = addb(justpath(tcmdbfile)) + subs(sys(2015),3) + [.mdb]

rename (tcmdbfile) to (lctmpfile)

if !file(tcmdbfile) and file(lctmpfile)

lc***poldstr = [provider=microsoft.jet.oledb.4.0] ;

+   [;data source=] + lctmpfile ;

+   [;jet oledb:database password=] + tcoldpswd

lc***pnewstr = [provider=microsoft.jet.oledb.4.0] ;

+   [;data source=] + tcmdbfile ;

+   [;jet oledb:database password=] + t**ewpswd

loengine = createobject( [jro.jetengine] )

loengine.***pactdatabase( lc***poldstr, lc***pnewstr )

release loengine

loengine = null

if file(tcmdbfile)

erase (lctmpfile)

else

rename (lctmpfile) to (tcmdbfile)

endif

else

isok = .f.

endif

on error &lcolderror.

endif

return isok and file(tcmdbfile)

endfunc

* --------------------------------------------

function changemdbpassword ( tcmdbfile, tcoldpswd, t**ewpswd )

* 修改 access 資料庫的密碼,必須獨佔開啟資料庫,使用前請確保沒有其他程式使用資料庫

local isok

isok = .f.

lcretustr =

tcmdbfile = iif(type([tcmdbfile])=[c], tcmdbfile, )

tcoldpswd = iif(type([tcoldpswd])=[c], tcoldpswd, )

t**ewpswd = iif(type([t**ewpswd])=[c], t**ewpswd, )

if file( tcmdbfile )

isok = .t.

local loadodb, lcolderror

lcolderror = on([error])

on error isok = .f.

loadodb = createobject( [adodb.connection] )

loadodb.mode = 12

loadodb.provider = [microsoft.jet.oledb.4.0]

loadodb.properties([jet oledb:database password]) = tcoldpswd

loadodb.open([data source=] + tcmdbfile)

loadodb.execute('alter database password [' + t**ewpswd + '][' + tcoldpswd + ']')

loadodb.close

release loadodb

loadodb = null

on error &lcolderror.

endif

return isok

endfunc

* --------------------------------------------

壓縮access資料庫

遇到一個問題,使用的是accesss資料庫,在載入資料庫中的資訊的時候,速度特別慢,有時候一次查詢最終會卡15秒左右,然後才能得到結果,跟蹤發現卡的地方在sqlexecdirect中,已經是odbc api了。開啟資料庫看也沒發現啥問題,後來點了access上邊的 壓縮和修復資料庫 工具,資料庫從原...

Delphi 壓縮Access資料庫

由於access資料庫在反覆使用過程中會自動增大,delphi壓縮access資料庫的簡單方法如下 首先要引用comobj單元 function tform1.compac b const dbfile,pwd string boolean var tempdbfile string constr ...

C 壓縮Access資料庫

壓縮資料庫 資料庫連結 要壓縮的mdb檔案的全名 static void compactaccessdb string dbfilename objjro.gettype invokemember compactdatabase system.reflection.bindingflags.invo...

用Delphi 壓縮Access資料庫

uses dao97,dao2000 procedure pac bdatabase srcdbname,dstdbname,oldpwd,newpwd string baccess97 boolean true var idbengine dbengine begin if oldpwd then...

壓縮access資料庫的方法。

stdafx.h import c program files common files system ado msjro.dll no namespace cstring strold cstring strnew char str3 1024 strold.format provider mic...