ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • 帮助
  • Sign Out
ArcGIS Desktop

ArcGIS Online

专为贵组织打造的制图平台

ArcGIS Desktop

全面的专业性 GIS

ArcGIS Enterprise

面向企业的 GIS

ArcGIS for Developers

用于构建位置感知应用程序的工具

ArcGIS Solutions

适用于行业的免费模板地图和应用程序

ArcGIS Marketplace

获取适用于组织的应用程序和数据

  • 文档
  • 支持
Esri
  • 登录
user
  • 我的个人资料
  • 登出

帮助

  • 主页
  • 入门
  • 地图
  • 分析
  • 管理数据
  • 工具
  • 其他...

将登录帐户和用户添加到 SQL Server

  • 添加可创建数据的用户
  • 使用 SQL Server 工具创建登录帐户和用户

在 Microsoft SQL Server 中,数据库管理员可将登录帐户添加到 SQL Server 实例,并且这些登录帐户已映射到 SQL Server 实例上各个数据库中的用户。可创建表和要素类的数据库用户必须具有可在数据库中创建这些对象的所需权限,这些用户还必须具有方案,以便在其中创建对象。使用 ArcGIS 时,该方案的名称必须与数据库用户相同。

您可使用创建数据库用户工具或脚本执行以下所有操作:

  • 创建登录帐户或将其添加到 SQL Server 实例。
  • 创建映射到指定登录帐户的用户。
  • 为在数据库中指定的用户创建匹配的方案。
  • 向此用户授予足以在指定数据库中创建表、要素类和视图的权限。

添加可创建数据的用户

您可以运行 ArcGIS for Desktop 中的创建数据库用户工具或调用 Python 脚本中的工具来创建数据库用户,该用户可创建表、要素类以及视图。

必须通过对 SQL Server 实例具有 sysadmin 权限的用户帐户连接到数据库,才能运行创建数据库用户工具。

如果希望针对 Windows 登录帐户创建数据库用户,在运行此工具之前 Windows 登录帐户必须已经存在。

使用创建数据库用户工具

  1. 启动 ArcMap 或 ArcCatalog。
  2. 通过在 SQL Server 实例中具有 sysadmin 权限的登录帐户连接到数据库或地理数据库。
  3. 打开创建数据库用户工具。

    该工具位于“数据管理”工具箱的“地理数据库管理”工具集中。

  4. 指定输入数据库连接的数据库连接。
  5. 选择要创建经 SQL Server 验证的登录帐户还是使用现有经 Windows 验证的登录帐户。
    • 取消选中创建经操作系统验证的用户以创建经 SQL Server 验证的登录帐户。请注意,默认情况下,SQL Server 实例仅使用 Windows 身份验证。如果未将实例配置为使用 SQL Server 和 Windows 身份验证,选择创建经数据库验证的登录帐户将失败。
    • 选中创建经操作系统验证的用户以使用现有经 Windows 验证的登录帐户。
  6. 为此工具将要创建的数据库用户输入名称。

    如果选择创建经 SQL Server 验证的登录帐户,您在此处输入的名称也将用于该登录帐户。

  7. 为数据库用户输入密码。
  8. 如果您已具有数据库角色并希望将此用户添加到角色,请指定该用户的角色。
  9. 单击确定运行工具。

运行 Python 脚本

若要编写用户创建的脚本,请按照以下步骤操作:

  1. 在 ArcGIS 客户端计算机上创建文本文件,然后将以下脚本复制到此文件。

    """
    Name: create_database_user.py
    Description: Provide connection information to a database user.
    Type create_database_user.py -h or create_database_user.py --help for usage
    Author: Esri
    """
    
    # Import system modules
    import arcpy
    import os
    import optparse
    import sys
    
    
    # Define usage and version
    parser = optparse.OptionParser(usage = "usage: %prog [Options]", version="%prog 1.0 for 10.1 release")
    
    #Define help and options
    parser.add_option ("--DBMS", dest="Database_type", type="choice", choices=['SQLSERVER', 'ORACLE', 'POSTGRESQL', ''], default="", help="Type of enterprise DBMS:  SQLSERVER, ORACLE, or POSTGRESQL.")                   
    parser.add_option ("-i", dest="Instance", type="string", default="", help="DBMS instance name")
    parser.add_option ("-D", dest="Database", type="string", default="none", help="Database name:  Not required for Oracle")
    parser.add_option ("--auth", dest="Account_authentication", type ="choice", choices=['DATABASE_AUTH', 'OPERATING_SYSTEM_AUTH'], default='DATABASE_AUTH', help="Authentication type options (case-sensitive):  DATABASE_AUTH, OPERATING_SYSTEM_AUTH.  Default=DATABASE_AUTH")
    parser.add_option ("-U", dest="Dbms_admin", type="string", default="", help="DBMS administrator user")
    parser.add_option ("-P", dest="Dbms_admin_pwd", type="string", default="", help="DBMS administrator password")
    parser.add_option ("--utype", dest="user_type", type ="choice", choices=['DATABASE_USER', 'OPERATING_SYSTEM_USER'], default='DATABASE_USER', help="Authentication type options (case-sensitive):  DATABASE_USER, OPERATING_SYSTEM_USER.  Default=DATABASE_USER")
    parser.add_option ("-u", dest="dbuser", type="string", default="", help="database user name")
    parser.add_option ("-p", dest="dbuser_pwd", type="string", default="", help="database user password")
    parser.add_option ("-r", dest="role", type="string", default="", help="role to be granted to the user")
    parser.add_option ("-t", dest="Tablespace", type="string", default="", help="Tablespace name")
    # Check if value entered for option
    try:
    	(options, args) = parser.parse_args()
    
    	#Check if no system arguments (options) entered
    	if len(sys.argv) == 1:
    		print "%s: error: %s\n" % (sys.argv[0], "No command options given")
    		parser.print_help()
    		sys.exit(3)
    
    	#Usage parameters for spatial database connection
    	database_type = options.Database_type.upper()
    	instance = options.Instance
    	database = options.Database.lower()	
    	account_authentication = options.Account_authentication.upper()
    	dbms_admin = options.Dbms_admin
    	dbms_admin_pwd = options.Dbms_admin_pwd
    	dbuser = options.dbuser
    	dbuser_pwd = options.dbuser_pwd	
    	tablespace = options.Tablespace
    	user_type = options.user_type
    	role = options.role
    
    	
    	if (database_type == "SQLSERVER"):
    		database_type = "SQL_SERVER"
    	
    	if( database_type ==""):	
    		print(" \n%s: error: \n%s\n" % (sys.argv[0], "DBMS type (--DBMS) must be specified."))
    		parser.print_help()
    		sys.exit(3)		
    	
    	if(database_type == "SQL_SERVER"):
    		if( account_authentication == "DATABASE_AUTH" and dbms_admin == ""):
    			print("\n%s: error: %s\n" % (sys.argv[0], "DBMS administrator must be specified with database authentication"))
    			sys.exit(3)
    		if( account_authentication == "OPERATING_SYSTEM_AUTH" and dbms_admin != ""):
    			print("\nWarning: %s\n" % ("Ignoring DBMS administrator specified when using operating system authentication..."))
    	else:		
    		if( dbuser.lower() == ""):
    			print("\n%s: error: %s\n" % (sys.argv[0], "Database user must be specified."))
    			sys.exit(3)		
    		if( dbms_admin == ""):
    			print("\n%s: error: %s\n" % (sys.argv[0], "DBMS administrator must be specified!"))
    			sys.exit(3)
    
    	if ( user_type == "DATABASE_USER" and (dbuser =="" or dbuser_pwd =="")):
    		print(" \n%s: error: \n%s\n" % (sys.argv[0], "To create database authenticated user, user name and password must be specified!"))
    		parser.print_help()
    		sys.exit(3)	
    
    	# Get the current product license
    	product_license=arcpy.ProductInfo()
    	
    	# Checks required license level
    	if product_license.upper() == "ARCVIEW" or product_license.upper() == 'ENGINE':
    		print("\n" + product_license + " license found!" + "  Creating a user in an enterprise geodatabase or database requires an ArcGIS for Desktop Standard or Advanced, ArcGIS Engine with the Geodatabase Update extension, or ArcGIS for Server license.")
    		sys.exit("Re-authorize ArcGIS before creating a database user.")
    	else:
    		print("\n" + product_license + " license available!  Continuing to create...")
    		arcpy.AddMessage("+++++++++")
    
    	# Local variables
    	instance_temp = instance.replace("\\","_")
    	instance_temp = instance_temp.replace("/","_")
    	instance_temp = instance_temp.replace(":","_")
    	Conn_File_NameT = instance_temp + "_" + database + "_" + dbms_admin   
    
    	if os.environ.get("TEMP") == None:
    		temp = "c:\\temp"	
    	else:
    		temp = os.environ.get("TEMP")
    	
    	if os.environ.get("TMP") == None:
    		temp = "/usr/tmp"		
    	else:
    		temp = os.environ.get("TMP")  
    
    	Connection_File_Name = Conn_File_NameT + ".sde"
    	Connection_File_Name_full_path = temp + os.sep + Conn_File_NameT + ".sde"
    	
    	# Check for the .sde file and delete it if present
    	arcpy.env.overwriteOutput=True
    	if os.path.exists(Connection_File_Name_full_path):
    		os.remove(Connection_File_Name_full_path)
    
    	try:
    		print("\nCreating Database Connection File...\n")
    		# Process: Create Database Connection File...
    		# Usage:  out_file_location, out_file_name, DBMS_TYPE, instnace, database, account_authentication, username, password, save_username_password(must be true)
    		#arcpy.CreateDatabaseConnection_management(temp , Connection_File_Name, database_type, instance, database, account_authentication, dbms_admin, dbms_admin_pwd, "TRUE")
    		arcpy.CreateDatabaseConnection_management(out_folder_path=temp, out_name=Connection_File_Name, database_platform=database_type, instance=instance, database=database, account_authentication=account_authentication, username=dbms_admin, password=dbms_admin_pwd, save_user_pass="TRUE")
    	        for i in range(arcpy.GetMessageCount()):
    			if "000565" in arcpy.GetMessage(i):   #Check if database connection was successful
    				arcpy.AddReturnMessage(i)
    				arcpy.AddMessage("\n+++++++++")
    				arcpy.AddMessage("Exiting!!")
    				arcpy.AddMessage("+++++++++\n")
    				sys.exit(3)            
    			else:
    				arcpy.AddReturnMessage(i)
    				arcpy.AddMessage("+++++++++\n")
    
    		print("Creating database user...\n")
    		arcpy.CreateDatabaseUser_management(input_workspace=Connection_File_Name_full_path, user_authentication_type=user_type, user_name=dbuser, user_password=dbuser_pwd, role=role, tablespace_name=tablespace)
    		for i in range(arcpy.GetMessageCount()):
    			arcpy.AddReturnMessage(i)
    		arcpy.AddMessage("+++++++++\n")
    	except:
    		for i in range(arcpy.GetMessageCount()):
    			arcpy.AddReturnMessage(i)
    			
    #Check if no value entered for option	
    except SystemExit as e:
    	if e.code == 2:
    		parser.usage = ""
    		print("\n")
    		parser.print_help()   
    		parser.exit(2)
    

    您可以在安装了 ArcGIS for Desktop(Standard 或 Advanced)、ArcGIS for Server(Standard 或 Advanced)或具有 Geodatabase Update 扩展模块的 ArcGIS Engine 的计算机上运行脚本。

  2. 以 .py 扩展名保存该文件。
  3. 运行脚本,同时提供特定于 SQL Server 实例和所要创建用户的选项和信息。

    在以下示例中,脚本名称为 create_database_user.py。在 SQL Server 实例 ssi5 中创建经 SQL Server 验证的登录帐户 (gisd_owner),并且在数据库 gisdata 中创建相应的用户和方案。未将此用户添加到角色。

    create_database_user.py --DBMS SQL_SERVER -i ssi5 -D gisdata --auth DATABASE_AUTH -U sa -P !nocopy! --utype DATABASE_USER -u gisd_owner -p T3mpPass
    

    提示:

    在命令提示符处输入 -h 或 --help 以获取语法帮助。

此时,数据库已具有可创建表的用户。

数据所有者可在数据库或地理数据库中以多种方式创建表。有关使用 ArcGIS 创建表的信息,请参阅将数据集添加到地理数据库的概述。

如果已存在数据集,数据所有者可向其他用户授予数据集的权限。有关说明,请参阅授予和撤消数据集权限。

使用 SQL Server 工具创建登录帐户和用户

您可以使用 SQL Server 工具创建用户,该用户的权限可不同于由创建数据库用户工具所授予的权限,或不具有直接授予的任何权限。创建自己的登录帐户和用户以与 ArcGIS 结合使用时,请牢记以下注意事项:

  • 将创建数据的所有数据库用户必须在数据库中具有方案。该方案的名称必须与用户名相同。
  • 您可以将 SQL Server 的访问权限授予 Windows 组(而不是单个 Windows 登录帐户),从而简化登录帐户的创建和管理。Windows 组的所有成员都可以登录到 SQL Server。授予组的服务器、数据库和数据集权限都会自动应用于组中的每个成员。但请注意,您不能只创建一个方案来存储所有组成员创建的数据。组中在地理数据库内创建数据的每个用户都必须具有自己的方案,以用于存储数据。在组成员首次创建数据时,SQL Server 在数据库中创建用户和方案。此操作自动进行;不必手动创建方案和用户。

有关使用 SQL Server 工具创建登录帐户、用户和方案的说明,请参阅 Microsoft SQL Server 文档。

ArcGIS Desktop

  • 主页
  • 文档
  • 支持

ArcGIS 平台

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

关于 Esri

  • 关于我们
  • 招贤纳士
  • Esri 博客
  • 用户大会
  • 开发者峰会
Esri
分享您的想法。
Copyright © 2019 Esri. | 隐私政策 | 法律声明