如何检入Access VBA, ODBC SQL Server表是否有写访问?

时间:2023-02-08 11:43:53

I have a ODBC Linked table in Microsoft Access which is connected to sql server.

我在Microsoft Access中有一个ODBC链接表,它连接到sql server。

For some users the login which connect access to SQL Server has access to only one database with db_datareader role so they cannot edit any data in the tables. For other users they have db_datareader + db_datawriter role and they can edit any data.

对于某些用户来说,连接SQL Server的登录只能访问一个具有db_datareader角色的数据库,因此不能编辑表中的任何数据。对于其他用户,他们有db_datareader + db_datawriter角色,可以编辑任何数据。

How can I check in vba that my table is not editable in case of db_datareader logins?

在db_datareader登录的情况下,我如何在vba中检查我的表是不可编辑的?

1 个解决方案

#1


3  

You can use passthrough queries to get user role membership, and querydefs to create or access them:

您可以使用passthrough查询来获得用户角色成员资格,以及querydefs创建或访问它们:

Public Function is_datawriter() As Boolean
    Dim qdef As DAO.QueryDef
    Dim rst As DAO.Recordset

    Set qdef = CurrentDb.CreateQueryDef("")
    qdef.Connect = "ODBC; MY_ODBC_CONN_STRING"
    qdef.SQL = "SELECT IS_ROLEMEMBER('db_datawriter')"
    Set rst = qdef.OpenRecordset(dbOpenDynaset)
    If rst.Fields(0).Value = 1 Then is_datawriter = True
End Function

Testing table-specific rights is somewhat more difficult, but in your case this will probably do.

测试特定于表的权限有些困难,但在您的例子中,这可能是可行的。

#1


3  

You can use passthrough queries to get user role membership, and querydefs to create or access them:

您可以使用passthrough查询来获得用户角色成员资格,以及querydefs创建或访问它们:

Public Function is_datawriter() As Boolean
    Dim qdef As DAO.QueryDef
    Dim rst As DAO.Recordset

    Set qdef = CurrentDb.CreateQueryDef("")
    qdef.Connect = "ODBC; MY_ODBC_CONN_STRING"
    qdef.SQL = "SELECT IS_ROLEMEMBER('db_datawriter')"
    Set rst = qdef.OpenRecordset(dbOpenDynaset)
    If rst.Fields(0).Value = 1 Then is_datawriter = True
End Function

Testing table-specific rights is somewhat more difficult, but in your case this will probably do.

测试特定于表的权限有些困难,但在您的例子中,这可能是可行的。