站长中国
设为首页 | 站长论坛

站长论坛 站长下载
您所在的位置: 站长中国 > 站长学院 > 数 据 库 > MSAccess >  正文

如何给ACCESS数据库添加PASSWORD?
  2007年10月15日21:42:00  评论(0条) 字体:[ ]
相关热点:

我用VB6的可视化数据管理器做一ACCESS数据库-------ACC1.MDB
用ADO如何给ACC1.MDB添加密码?
谢谢!
---------------------------------------------------------------

Working with Database Passwords in VBA Code
As an alternative to using the Access user interface to work with database passwords, you can use Data Access Objects (DAO) and ActiveX Data Objects (ADO) in VBA code.

Important   If you use code to open a database and a user later sets a database password without your being aware of it, your code will no longer be able to open the database. Your code should always check to see if the attempt to open a database has succeeded. The code should also provide error handling in case it encounters a password-protected database.

Setting, Changing, or Clearing a Database Password in Code
Unfortunately there is no way to set, change, or clear a database password by using ADO code. It is possible to set, change, or clear a database password when you are compacting a database by using the CompactDatabase method of the Microsoft Jet and Replication Objects 2.1 object library; however the CompactDatabase method requires you to create a second copy of the database to do so.

A simpler method of setting, changing, or clearing a database password is to use the NewPassword method of the DAO Database object. To work with the NewPassword method, you must set a reference to the Microsoft DAO 3.6 object library. Before you can work with a database password, you must be able to open the database in exclusive mode. To open a database by using exclusive access with DAO, set the Options argument of the OpenDatabase method to True. The following procedure opens a database in exclusive mode, and sets, changes, or clears a database password depending on what values you pass to it for the strOldPwd and strNewPwd arguments: 

To set a database password for a database that currently has no password, pass a zero-length string ("") for strOldPwd and the password you want to set for strNewPwd.


To change a database password, pass the current password for strOldPwd and the new password for strNewPwd.


To clear a database password, pass the current database password for strOldPwd and a zero-length string for strNewPwd. 
 Function SetDBPassword(strDBPath As String, _
                       strOldPwd As String, _
                       strNewPwd As String)
   ' This procedure sets a new password or changes an existing
   ' password.

   Dim dbsDB      As DAO.Database
   Dim strOpenPwd As String

   ' Create connection string by using current password.
   strOpenPwd = ";pwd=" & strOldPwd

   ' Open database for exclusive access by using current password. To get
   ' exclusive access, you must set the Options argument to True.
   Set dbsDB = OpenDatabase(Name:=strDBPath, _
                            Options:=True, _
                            ReadOnly:=False, _
                            Connect:=strOpenPwd)

   ' Set or change password.
   With dbsDB
      .NewPassword strOldPwd, strNewPwd
      .Close
   End With

   Set dbsDB = Nothing
End Function

The SetDBPassword procedure is available in the modSecurity module in AccessSecurity.mdb in the ODETools\V9\Samples\ODETools\V9\Samples\OPG\Samples\CH18 subfolder on the Office 2000 Developer CD-ROM. 

Opening a Password-Protected Database with ADO
To open an Access password-protected database by using ADO code, you specify the password by using the provider-specific Jet OLEDB:Database Password property. You can specify the Jet OLEDB:Database Password property by using the Properties collection of the Connection object, or as part of the connection string passed to the Open method of the Connection object. For example, the following procedure opens a password-protected database:

Function OpenProtectedDB(strDBPath As String, _
                         strPwd As String)
   Dim cnnDB As ADODB.Connection

   Set cnnDB = New ADODB.Connection

   ' Open database for shared (by default)


责任编辑:

收藏本文 打印 打印本文  推荐本文 告诉好友 投稿 投稿邮箱
    评论加载中…

站长排行

学院

新闻

专栏

盈利

[揭密网络黄链]中国留学生买凶专破日本
JSP语法(6)
超强弹出窗口代码,什么都挡不住
FLASH视觉特效实例之地震效果
贴吧发帖机使用教程(绝对原创)
关于数据分页(转自www.codeproject.co
ASP实现文件直接下载
Photoshop制作光感超酷效果水晶球
 遍历ASP.NET页面控件
永远的后门[经典]+查不出的后门
淘宝网卖家公然叫卖“艳照门”照片集
驳《百度Hi面世对腾讯有利》
Google绿色专家质疑黑色背景网页节省资
国内各IT企业办公环境揭秘(多图)
阿里妈妈广告卖主全攻略
站长创业源动力 主流站长站赏析
推荐阅读:80年小子的创业道理
Discuz!6.0猛将出击 最强论坛程序酷炫
我的网络,我的团队:专访李文明
百度新闻频道改版十天 流量止跌反弹翻
ECSHOP模板制作参考文档
悬挂阿里妈妈会否被百度惩罚
阿里妈妈是否是中小站长的救世主?
最强网店ECShop发新版 众多酷炫功能给
ECSHOP模板下载
土豆网,优酷网,爆米花等视频网站采集
DedeCms模板安装/制作概述
网上商店系统巅峰对决 ECShop vs ShopE
艰难的走在创业的路上 第一天
编程中国全站采集规则
性福联盟 一个不尊重站长的联盟
大脚:日赚100元—揭露最新firefox欺骗
大脚:垃圾站超级赚钱法之二—突破“站
大脚:垃圾站超级赚钱法之——前言
迅雷联盟、快车联盟收入对比
经理人必看的十个管理网站
Google Adsense的秘密 第二版
西联汇款兑付城市查询
不用SEO取得成功的10个步骤
关于做GOOGLE的五条经验
站长学院  网页设计 建站教程 图形图象 网络编程

Photoshop CS3
Photoshop CS3
不用Photoshop
不用Photoshop

DIV+CSS的开发方式 听听另外的
虚拟主机建站动易里快速生成的
VBScript特效代码 满屏幕乱跑
牛气!一个菜鸟站长的超强网站
创建、维护一个个人博客的“投
让网站流量稳步飙升的秘籍
网站推广的基本思想

新闻线索

如果你有站长界人事变动、重组并购、变革技术出现,以及产品投诉等重要新闻线索,请告诉我们,我们会给予特别关注。
0631-3653338
站长中国编辑部
站长中国24小时新闻热线: 13256307008