access数据库在一些小的系统程序中经常用到,为了给数据库中的信息增加一些安全性,最简单的方法就是给access文件加上密码(当然也可以 将数据库中的数据进行加密后在存放到文件里来保护数据,只不过这种方法需要在程序中考虑加密和解密的问题),那针对有密码的文件通过数据库连接字符串来进 行连接访问呢?下面是我在网络上找到的一些解决方案。收集起来以备后用。
access数据库加密分3种
以下以access xp为例
1、工具 -> 安全-> 加密/解密数据库,打开时无需任何更改
2、工具 -> 安全-> 设置数据库密码,打开密码为 1 打开时需要使用
provider=microsoft.jet.oledb.4.0;data source=c:\1.mdb;user id=admin;password=;jet oledb:database password=1
也可以用
provider=microsoft.jet.oledb.4.0;data source=c:\1.mdb;user id='admin';password=;jet oledb:database password='1'
3、工具 -> 安全-> 用户组与权限 .... ,用户名为 admin 密码为 rr 用户组文件为 c:\system.mdw,打开时需要使用
provider=microsoft.jet.oledb.4.0;data source=c:\1.mdb;user id=admin;password=rr;jet oledb:database password=1;jet oledb:system database=c:\system.mdw
也可以用
provider=microsoft.jet.oledb.4.0;data source=c:\1.mdb;user id='admin';password='rr';jet oledb:database password='1';jet oledb:system database=c:\system.mdw
如果在局域网上共享访问数据库,只要将绝对路径更改为 \\计算机名\共享目录名\文件名.mdb 即可,比如
provider=microsoft.jet.oledb.4.0;data source=\\access911\floder1\1.mdb;user id='admin';password='rr';jet oledb:database password='1';jet oledb:system database=\\access911\floder1\system.mdw
直接在连接字串里面定义 mode 属性达到独占/公享等目的也是可以的,比如:
jetoledb:globalpartialbulkops=2;jetoledb:registrypath=;jetoledb:databaselockingmode=1;jetoledb:databasepassword=;datasource=d:\db.mdb;password=;jetoledb:enginetype=5;jetoledb:globalbulktransactions=1;provider=microsoft.jet.oledb.4.0;jetoledb:systemdatabase=;jetoledb:sfp=false;extendedproperties=;mode=sharedenynone;jetoledb:newdatabasepassword=;jetoledb:createsystemdatabase=false;jetoledb:don'tcopylocaleoncompact=false;jetoledb:compactwithoutreplicarepair=false;userid=admin;jetoledb:encryptdatabase=false
注意:access 2007 在数据格式上有了很大变化,因此数据提供者已经不是 jet db 4.0 了,microsoft.ace.oledb.12.0 才是 *.accdb 的数据提供者。
provider=microsoft.ace.oledb.12.0;user id=admin;data source=c:\documents and settings\chenge\my documents\数据库1.accdb;mode=share deny read|share deny write;extended properties=;jet oledb:system database=c:\documents and settings\chenge\application data\microsoft\access\system.mdw;jet oledb:registry path=software\microsoft\office\12.0\access\access connectivity engine;jet oledb:database password=;jet oledb:engine type=6;jet oledb:database locking mode=0;jet oledb:global partial bulk ops=2;jet oledb:global bulk transactions=1;jet oledb:new database password=;jet oledb:create system database=false;jet oledb:encrypt database=false;jet oledb:don't copy locale on compact=false;jet oledb:compact without replica repair=false;jet oledb:sfp=false;jet oledb:support complex data=true
