Command line utility for granting and revoking privileges on geodatabase objects


It is often the case that in an enterprise system, utilizing a multi-user geodatabase, there are multiple database users to whom you need to grant and revoke database privileges on multiple objects. While this can be done using ArcCatalog, you may want to write a script that performs this process. This example demonstrates how implementing the ISQLPrivileges interface in a C++ console application allows you to create a command line utility for granting and revoking privileges.

How to use:
  1. View the source code to see how the utility was implemented.
  2. Open a command prompt and run the executable. You will be prompted with the following usage:
      Usage: GDB_Grant <Server> <Service> <Username> <Password> <Database>
             <Target_user> <R | RW | NONE> <Dataset_name>
      <Server> is the name of the server machine where ArcSDE and the geodabase are.
      <Service> is the name or the TCP/IP port address of the ArcSDE service.
      <Username> is the data username of the owner of the data which you are granting privileges on.
      <Password> is the data password of the owner of the data which you are granting privileges on.
      <Database> is the name of the database if ArcSDE is running on SQL Server or Informix
        (if ArcSDE is running on another DBMS, use # for this argument)
      <Target_user> is the name of the database user to whom you are granting or revoking privileges.
      <R | RW | NONE> is the level of access you want to provide the target user on the dataset specified.
        R = read-only (SELECT privileges)
        RW = read-write (SELECT, UPDATE, INSERT, DELETE privileges)
        NONE = no privileges
      <Dataset_name> is the name of the dataset that you want to grant or revoke privileges on.
      This can be a feature dataset, stand-alone feature class, table, or attributed relationship class. 
      Feature classes within feature datasets cannot be operated on individually with this tool,
      though ArcObjects code can be written to do this.
      GDBGrant mickey 5151 gdb gdb # water RW GrLandbase

Command line

Difficulty: Advanced

Visual C++
File Description
GDBGrant.dsw Visual C++ workspace that implements this sample.
main.cpp C++ source file.
GDBTools.cpp C++ source file of helper functions.
GDBTools.h C++ header file of helper functions.
GDBGrant.exe Compiled executable for the project.

Key Interfaces: ISQLPrivilege