'下面函数说明如何用代码自动设定连接表权限,运行此函数用户必须是管理组成员,此函数适用于ACCESS2.0/95/97/2000
'函数原理:先设定后端表权限,然后使用RefreshLink方法重连接后端表
'下面函数设定后端表读权限,后端数据库打开/运行权限,前端表及查询所有权限
'用法:登陆时运行此函数,确保正常登陆才能读后端数据,更好保护后端数据
'译自:Questions About Microsoft® Access Security Trans. by gnoy
Function faq_SetPermissions (strTable As String, strSourceDB As String, strUsrName As String)
' 参数:
' strTable
' 需要设定权限表名,假定前后端表名一
' strSourceDB
' 后端数据库全名
' strUsrName
' 欲刷新连接的用户组或用户名
'
Dim db As Database
Dim con As Container
Dim doc As Document
Dim ws As WorkSpace
Set ws = dbengine.workspaces(0)
' set default full permissions in destination
' (current) database for new tables
Set db = CurrentDB()
Set con = db.Containers("Tables")
con.username = strUsrName
con.permissions = DB_SEC_FULLACCESS
' set full permissions for the linked table
' in the destination database
Set doc = con.Documents(strTable)
doc.username = strUsrName
doc.permissions = DB_SEC_FULLACCESS
' Set open database permissions for the source database
Set db = ws.OpenDatabase(strSourceDB)
Set con = db.Containers("Databases")
Set doc = con.Documents("MSysdb")
doc.username = "Users"
doc.permissions = doc.permissions Or DB_SEC_DBOPEN
' Set read data permissions for the base table
Set con = db.Containers("Tables")
Set doc = con.Documents(strTable)
doc.username = strUsrName
doc.permissions = doc.permissions Or DB_SEC_RETRIEVEDATA
End Function
附刷新权限描述:
Minimum Permission Description for RefreshLink Access 2.0 Constants Access 95/97/2000
1. *The ability to create New Tables/ Queries in the destination database DB_SEC_CREATE DbSecCreate
2. *Read Design Permissions on the Table in the destination database DB_SEC_READDEF DbSecReadDef
3. *Read Data permissions on the table in the destination database DB_SEC_RETRIEVEDATA DbSecRetrieveData
4. Open/Run permissions for the source database DB_SEC_DBOPEN DbSecDBOpen
5. Read Data permissions on the table in the source database DB_SEC_RETRIEVEDATA DbSecRetrieveData
*Just set full permissions in the destination database DB_SEC_FULLACCESS DbSecFullAccess
'以上已经确保你有后端数据库表读权限,前端表及查询所有权限,现在我们就可以使用 RefreshLink方法重新连接后端表了.
'以下函数对后端数据库表有读权限以及对后端数据库有打开/运行的用户才能适用
Function faq_RefreshLink (strTable As String, strSourceDB As String)
' 参数:
' strTable
' 欲刷新的表名
' strSourceDB
' 后端数据库全名
'
Dim ws As WorkSpace
Dim db As Database
Dim tdf As TableDef
Set ws = dbengine.workspaces(0)
Set db = CurrentDB()
Set tdf = db.TableDefs(strTable)
' specify new location of source table
tdf.Connect = ";DATABASE=" & strSourceDB
' refresh the link
tdf.RefreshLink
End Function
[此贴子已经被gnoy于2002-9-22 13:01:24编辑过]
|