2024年5月30日发(作者:)
* --------------------------------------------
* 程序: 创建、压缩access数据库并修改密码演示
* 设计: 红雨
* --------------------------------------------
local lcmdbfile, lcretustr
lcmdbfile = [t:]
lcpswd1 = [test1]
lcpswd2 = [test2]
lcpswd3 = [test3]
lcretustr = [创建、压缩access数据库并修改密码演示:] + chr(13)
if createmdb( lcmdbfile, lcpswd1)
lcretustr = lcretustr + chr(13) + [1、创建数据库成功 - 密码: ] + lcpswd1
if compactmdb( 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( [g] )
lccmdstrs = [provider=.4.0] ;
+ [;data source=] + tcmdbfile ;
+ [;jet oledb:database password=] + tcpswdstr
( lccmdstrs )
release locatalog
locatalog = null
on error &lcolderror.
endif
return isok and file(tcmdbfile)
endfunc
* --------------------------------------------
function compactmdb ( tcmdbfile, tcoldpswd, tcnewpswd )
* 压缩 access 数据库并设置密码
local isok
isok = .f.
tcmdbfile = iif(type([tcmdbfile])=[C], tcmdbfile, [])
tcoldpswd = iif(type([tcoldpswd])=[C], tcoldpswd, [])
tcnewpswd = iif(type([tcnewpswd])=[C], tcnewpswd, tcoldpswd)
if file( tcmdbfile )
isok = .t.
local loengine, lctmpfile, lcolderror, lccompoldstr, lccompnewstr
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)
lccompoldstr = [provider=.4.0] ;
+ [;data source=] + lctmpfile ;
+ [;jet oledb:database password=] + tcoldpswd
lccompnewstr = [provider=.4.0] ;
+ [;data source=] + tcmdbfile ;
+ [;jet oledb:database password=] + tcnewpswd
loengine = createobject( [ine] )
tdatabase( lccompoldstr, lccompnewstr )
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, tcnewpswd )
发布评论