Program: Create, compress the Access database and modify the password demo

xiaoxiao2021-03-06  115

* ------------------------------------------ * Program: Created, Compress Access database and modify password demonstration * Design: Red rain * --------------------------------------- ------- local lcmdbfile, lcretustrlcmdbfile = [c: /temp/testcreamdbfile.mdb] lcpswd1 = [test1] lcpswd2 = [test2] lcpswd3 = [test3] lcretustr = [Create, compress the Access database and modify the password: ] CHR (13)

If createmdb (lcmdbfile, lcpswd1) LCRETUSTR = LCRETUSTR CHR (13) [1, create a database success - password:] lcpswd1 if CompactMDB (LCMDBFILE, LCPSWD1, LCPSWD2) Lcretustr = LCRETUSTR CHR (13) [2, compression And change the password success - password:] lcpswd2 if changeMdbpassword (lcmdbfile, lcpswd2, lcpswd3) LCRETUSTR = LCRETUSTR CHR (13) [3, separately modify the database password success - password:] lcpswd3 else lcretustr = lcretustr CHR (13 ) [3, separately modify the database password] Endif else lcretustr = LCRETUSTR CHR (13) [2, compression and modify password failed] endifelse lcretustr = LCRETUSTR CHR (13) [1, create database failed] Endif

= MessageBox (Lcretustr, 0 64 0, [Red Rain Tips]) Return

* ------------------------------------------ Function Createmdb (TCMDBFILE, TCPswdstr) * Create an Access Database file (.mdb) local isok isok = .f. tcmdbfile = IIF (Type ([TCMDBFILE]) = [C], TCMDBFILE, []) TCPswdstr = IIF (Type ([TCPswdstr] = [ C], tcpswdstr, []) IF file (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 CompactMDB (TCMDBFILE, TCOLDPSWD, TCNEWPSWD) * Compress the Access database and set the password 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) ing! File (tcmdbfile) and File (lcTmpFile) lcCompOldStr = [Provider = Microsoft.Jet.OLEDB.4.0]; ​​[; Data Source =] lcTmpFile; [; Jet OLEDB: Database Password =] tcOldPswd lcCompNewStr = [Provider = Microsoft.Jet. OLEDB.4.0]; ​​[Data Source =] TCMDBFILE; [JET OLEDB: Database Passw ord =] tcNewPswd loEngine = CreateObject ([JRO.JetEngine]) loEngine.CompactDatabase (lcCompOldStr, lcCompNewStr) Release loEngine loEngine = Null If File (tcMdbFile) Erase (lcTmpFile) Else Rename (lcTmpFile) To (tcMdbFile) Endif Else IsOK = Endif On Error & LcoldError. Endif Return Isok and File (TCMDBFILE) Endfunc

* ------------------------------------------ Function Changemdbpassword (TCMDBFILE, TCOLDPSWD, TCNEWPSWD) * Modify the password of the Access database, must be exclusively open database, make sure not other programs use database local isok isok = .f. lcretustr = [] tcmdbfile = IIF (Type (TCMDBFILE]) = [c] , tcmdbfile, []) TCOLDPSWD = IIF (Type ([TCOLDPSWD]) = [C], TCOLDPSWD, []) TcnewPswd = IIF (Type ([TcnewPswd]) = [C], TcneWPswd, []) 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 [' tcNewPswd '] [' tcOldPswd ' ] ') ​​Loadodb.close release loadodb loadodb = null on error & lcolderror. Endif return isokenDfunc * ---------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------

转载请注明原文地址:https://www.9cbs.com/read-100279.html

New Post(0)