Create a geodatabase in SQL Server

Available with Standard or Advanced license.

To create a geodatabase in a Microsoft SQL Server database, you run a geoprocessing tool or Python script from an ArcGIS client.

When you create a geodatabase from ArcGIS AllSource 3.3, the geodatabase version is 11.3.0.

Start by reading the prerequisites, then follow the instructions that apply to your situation.

Prerequisites

To create a geodatabase SQL Server, do the following:

  1. Confirm that the ArcGIS, SQL Server, and operating system combinations you want to use are compatible.
  2. Download the SQL Server ODBC client required to connect to the version of SQL Server you'll use to store the geodatabase.
  3. Obtain an ArcGIS Server keycodes file and place it in a location you can access from the ArcGIS client you'll use to create the geodatabase.
  4. Determine who will create the geodatabase, as that affects who creates the database and which tool you run to create the geodatabase. Follow the instructions that apply to your situation:

You are the SQL Server and geodatabase administrator

If you perform the role of both the database administrator and geodatabase administrator and, therefore, know the password for both logins, you can use the Create Enterprise Geodatabase geoprocessing tool or Python script to create a geodatabase in a SQL Server database.

The Create Enterprise Geodatabase tool makes it easy to set up a geodatabase because it creates the database objects and grants required privileges for you. To achieve this, the tool uses the following default settings and creates the following database objects:

  • It creates the database files (MDF and LDF) in the default SQL Server location on the server.
  • It sets the SQL Server database options READ_COMMITTED_SNAPSHOT and ALLOW_SNAPSHOT_ISOLATION to ON.
  • It uses the default database file sizes you have defined for the SQL Server model database or 500 MB for the MDF file and 125 MB for the LDF file, whichever is greater.
  • If you choose to create a geodatabase in a schema named sde, the tool creates an sde database-authenticated login in the SQL Server instance, creates an sde user in the database and maps it to the sde login, creates an sde schema in the database, and grants the sde user privileges to create a geodatabase and drop connections to the SQL Server instance.
  • It creates the geodatabase objects inside the SQL Server instance.

Before you run the tool or script to create a geodatabase, you must install and configure a SQL Server instance.

Install and configure SQL Server

Before you create a geodatabase, SQL Server must be installed and the instance configured. How you configure the instance depends on the needs of your organization.

Note:

The SQL Server instance must use a case-insensitive collation, and the database cannot use a Turkish collation.

Once you (or the IT department) install SQL Server, be sure you configure the SQL Server instance to accept remote connections; by default, remote connections are not enabled.

Consult Microsoft documentation for SQL Server installation and configuration information.

After SQL Server is installed and configured, install ArcGIS and SQL Server clients.

Install clients

You can install ArcGIS AllSource (Desktop Standard or Desktop Advanced) or ArcGIS Server (enterprise edition) and run a Python script to create a geodatabase. To run the Create Enterprise Geodatabase geoprocessing tool instead of a script, install ArcGIS AllSource.

Note:

You need an ArcGIS Server (enterprise edition) keycodes file to authorize your geodatabase in the next section. Even if you do not run a Python script from an ArcGIS Server machine to create the geodatabase, install and authorize ArcGIS Server to get the keycodes file. You may have to copy the keycodes file from the ArcGIS Server machine to a location the Create Enterprise Geodatabase geoprocessing tool can access.

In most cases, your ArcGIS clients are installed on a different computer than SQL Server. Therefore, you must have a supported SQL Server client installed on the ArcGIS client computer to connect to the database. See ArcGIS system requirements for SQL Server to determine which version SQL Server client you should install to connect to the version of SQL Server you are using.

To connect to SQL Server on a Microsoft Windows machine, you can download the SQL Server client from My Esri or from the Microsoft Download Center. To connect to SQL Server on a Linux machine, download the SQL Server client files from the Microsoft Download Center. Follow the instructions from Microsoft to install the SQL Server client on your client machine.

Follow these steps to install and configure the client you need to create the geodatabase. If you do not have permissions to install software, have your IT department perform these steps.

  1. Install the ArcGIS client you want to use for geodatabase creation.

    Follow the instructions provided in the software installation guides.

  2. Install a SQL Server client on the ArcGIS client computer.

    When you install the SQL Server client on a 64-bit operating system, use the 64-bit SQL Server client executable. If you run the 32-bit SQL Serverclient on a 64-bit operating system, installation will fail.

Now you can create a geodatabase.

Create a geodatabase

You can run the Create Enterprise Geodatabase tool from ArcGIS AllSource (Desktop Standard or Desktop Advanced), or run a Python script from an ArcGIS AllSource (Desktop Standard or Desktop Advanced) or ArcGIS Server (enterprise edition) client to create both a database and geodatabase.

Run the Create Enterprise Geodatabase tool

If you have access to ArcGIS AllSource, you can run a geoprocessing tool to create the geodatabase.

Follow these steps to create a geodatabase using the Create Enterprise Geodatabase tool in ArcGIS AllSource:

  1. Start ArcGIS AllSource.
  2. Open the Create Enterprise Geodatabase tool.

    You can search for or browse to this tool, which is located in the Geodatabase Administration toolset of the Data Management toolbox.

  3. Choose SQL Server from the Database Platform drop-down list.
  4. Type the name of the SQL Server instance to which you will connect in the Instance text box.
  5. In the Database text box, type the name of the database where you want to store your geodatabase.

    If a database with that name does not exist in the SQL Server instance, the tool creates it. If the database exists, the tool uses it to store the geodatabase.

  6. Connect to SQL Server as a system administrator. Use either an operating system-authenticated login that is a member of the sysadmin fixed server role in SQL Server or type a database username and password for a sysadmin user.
    • To authenticate using a sysadmin operating system-authenticated login, check Operating System Authentication. You must be signed in to Windows with the correct login to use this option.
    • To authenticate as sysadmin, type the sysadmin username in the Database Administrator text box and the corresponding password in the Database Administrator Password text box.
  7. Choose the schema that will contain the geodatabase.
    • If you want a user named sde to be the geodatabase administrator and the geodatabase to be stored in the sde user's schema, check Sde Owned Schema.
    • If you want the dbo user to be the geodatabase administrator and the geodatabase to be stored in the dbo schema, uncheck Sde Owned Schema.

    For more information on storing the geodatabase in either the sde or dbo schema, see Comparison of geodatabase owners in SQL Server.

  8. If you choose an sde-owned schema, the Geodatabase Administrator text box is populated with sde. If a user with that name does not exist, the tool creates the user and its corresponding schema and grants the user the privileges required to create a geodatabase.

    If you are using database authentication and a dbo schema to store the geodatabase, type the name of a user who is dbo in the SQL Server instance in the Geodatabase Administrator text box.

    If you are using operating system authentication to connect to the database, your current login must be in the SQL Server sysadmin fixed-server role to create a dbo-schema geodatabase.

  9. Type a password for the geodatabase administrator in the Geodatabase Administrator Password text box.

    If the geodatabase administrator you specified already exists in the database, be sure to type the correct password for the existing user; this tool does not change the password.

  10. To specify an Authorization File, browse to and choose the keycodes file that was created when you authorized ArcGIS Server (enterprise edition).

    This file is created in the \\Program Files\ESRI\License<release#>\sysgen folder on Windows servers and /arcgis/server/framework/runtime/.wine/drive_c/Program Files/ESRI/License<release#>/sysgen on Linux servers. Copy the keycodes file to a location you can access with the Create Enterprise Geodatabase tool. If you have not already done so, authorize ArcGIS Server now to create this file.

  11. Click Run.

A database and log files are created in the default SQL Server location if you did not specify an existing database. A geodatabase is created in the database. If you chose an sde-schema geodatabase, a database-authenticated sde login, database user, and schema are created.

Messages related to geodatabase creation are written to the sde_setup.log file, which is created in the directory specified for your %TEMP% variable on the computer where the tool is run. If you have any problems creating a geodatabase, check this file to troubleshoot the problem.

Next, you can create a user who can load data into the geodatabase.

Run a Python script

You can copy, save, and run the script provided here to create a geodatabase from ArcGIS AllSource (Standard or Advanced) or ArcGIS Server (enterprise edition).

  1. Create a text file on the ArcGIS client machine and copy the following script into the file:
    """
    Name: create_enterprise_gdb.py
    Description: Provide connection information to a DBMS instance and create an enterprise geodatabase.
    Type  create_enterprise_gdb.py -h or create_enterprise_gdb.py --help for usage
    Author: Esri
    """
    
    # Import system modules
    import arcpy, os, optparse, sys
    
    
    # Define usage and version
    parser = optparse.OptionParser(usage = "usage: %prog [Options]", version="%prog 1.0 for 10.1 and higher releases")
    
    #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 ("--schema", dest="Schema_type", type="choice", choices=['SDE_SCHEMA', 'DBO_SCHEMA'], default="SDE_SCHEMA", help="Schema Type for SQL Server geodatabase, SDE or DBO. Default=SDE_SCHEMA")
    parser.add_option ("-u", dest="Gdb_admin", type="string", default="", help="Geodatabase administrator user name")
    parser.add_option ("-p", dest="Gdb_admin_pwd", type="string", default="", help="Geodatabase administrator password")
    parser.add_option ("-t", dest="Tablespace", type="string", default="", help="Tablespace name")
    parser.add_option ("-l", dest="Authorization_file", type="string", default="", help="Full path and name of authorization file")
    parser.add_option ("--type", dest="Spatial_type", type="choice", choices=['ST_GEOMETRY', 'POSTGIS'], default="ST_GEOMETRY", help="Spatial Type for PostgreSQL geodatabase, ST_GEOMETRY or POSTGIS. Default=ST_GEOMETRY")
    
    # 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
    	schema_type = options.Schema_type.upper()
    	gdb_admin = options.Gdb_admin
    	gdb_admin_pwd = options.Gdb_admin_pwd	
    	tablespace = options.Tablespace
    	license = options.Authorization_file
    	spatial_type = options.Spatial_type.upper()
    	
    	
    	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 (license == ""):
    		print(" \n%s: error: \n%s\n" % (sys.argv[0], "Authorization file (-l) must be specified."))
    		parser.print_help()
    		sys.exit(3)			
    	
    	if(database_type == "SQL_SERVER"):
    		if(schema_type == "SDE_SCHEMA" and gdb_admin.lower() != "sde"):
    			print("\n%s: error: %s\n" % (sys.argv[0], "To create SDE schema on SQL Server, geodatabase administrator must be SDE."))
    			sys.exit(3)
    		if (schema_type == "DBO_SCHEMA" and gdb_admin != ""):
    			print("\nWarning: %s\n" % ("Ignoring geodatabase administrator specified when creating DBO schema..."))
    		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 (schema_type == "DBO_SCHEMA"):
    			print("\nWarning: %s %s, %s\n" % ("Only SDE schema is supported on", database_type, "switching to SDE schema..." ))
    			
    		if( gdb_admin.lower() == ""):
    			print("\n%s: error: %s\n" % (sys.argv[0], "Geodatabase administrator 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 (account_authentication == "OPERATING_SYSTEM_AUTH"):
    			print("Warning: %s %s, %s\n" % ("Only database authentication is supported on", database_type, "switching to database authentication..." ))
    
    	# 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 an enterprise geodatabase 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 enterprise geodatabase.")
    	else:
    		print("\n" + product_license + " license available!  Continuing to create...")
    		arcpy.AddMessage("+++++++++")
    	
    	
    	try:
    		print("Creating enterprise geodatabase...\n")
    		arcpy.management.CreateEnterpriseGeodatabase(database_platform=database_type,instance_name=instance, database_name=database, account_authentication=account_authentication, database_admin=dbms_admin, database_admin_password=dbms_admin_pwd, sde_schema=schema_type, gdb_admin_name=gdb_admin, gdb_admin_password=gdb_admin_pwd, tablespace_name=tablespace, authorization_file=license, spatial_type=spatial_type)
    		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)
  2. Save the file with a .py extension.
  3. Run the script, providing options and information specific to your site.

    In the following example, the file create_gdb.py is run to create the database, entgdb, on the porthos\gisprod SQL Server instance. The tool is run as the sa user, using database authentication, and it creates a geodatabase in the sde user's schema. A keycodes file in the default ArcGIS Server location is specified to authorize the geodatabase.

    create_gdb.py --DBMS SQL_SERVER -i porthos\gisprod -D entgdb --auth DATABASE_AUTH 
    -U sa -P N0pe3king! --schema SDE_SCHEMA -u sde -p Tgdbst@rtsh3r3 -l '\\Program Files\ESRI\License\sysgen\keycodes'

    In this example, the same script is run while signed in to the client machine with a login that is a member of the sysadmin fixed-server role to create a geodatabase in the dbo schema:

    create_gdb.py --DBMS SQL_SERVER -i porthos\gisprod -D entgdb --auth OPERATING_SYSTEM_AUTH 
    --schema DBO_SCHEMA -l '\\Program Files\ESRI\License\sysgen\keycodes'
    Tip:

    Type -h or --help at the command prompt to get syntax help.

You now have a geodatabase in SQL Server.

Messages related to geodatabase creation are written to the sde_setup.log file, which is created in the directory specified for your %TEMP% variable on the computer where the script is run. If you have any problems creating a geodatabase, check this file to troubleshoot the problem.

Next, you can create a user who can load data into the geodatabase.

The SQL Server administrator creates the database; the geodatabase administrator creates the geodatabase

If the person creating the geodatabase does not have access to the database administrator's password, the database administrator can create the database and the geodatabase administrator's login, user, and schema. If the geodatabase is to be stored in the sde schema, the database administrator creates an sde login, user, and schema. If the geodatabase is to be stored in the dbo schema, the database administrator creates a login and user, and assigns the user to be the owner of the database. See Comparison of geodatabase owners in SQL Server for information on geodatabase storage options.

The geodatabase administrator can connect to the database as the geodatabase administrator and create a geodatabase using the Enable Enterprise Geodatabase geoprocessing tool or Python script.

The Enable Enterprise Geodatabase tool takes a database connection file as input and creates the geodatabase system tables, views, functions, and procedures.

Install and configure SQL Server

Before the geodatabase administrator can create a geodatabase, the SQL Server administrator must do the following:

  • Install SQL Server and configure the instance. How you configure the instance depends on the needs of your organization. Check the ArcGIS system requirements before you proceed to ensure the database management system, ArcGIS, and hardware combinations you want to use are supported. Once you install SQL Server, be sure you configure the SQL Server instance to accept remote connections; by default, remote connections are not enabled. Consult Microsoft documentation for SQL Server installation and configuration information.

    Note:

    The SQL Server instance must use a case-insensitive collation, and the database cannot use a Turkish collation.

  • Create a database.
  • Set the SQL Server database options READ_COMMITTED_SNAPSHOT and ALLOW_SNAPSHOT_ISOLATION to ON. If the SQL Server administrator does not set these options to ON but grants the geodatabase administrator ALTER permissions in the database, the Enable Enterprise Geodatabase tool changes these settings on the database when it is run. If the SQL Server administrator does not set these options, and the geodatabase administrator does not have sufficient permissions to change them, geodatabase creation fails.
  • Add or create a login that is mapped to a database user named sde or to a database user who is the database owner.
  • If using an sde-schema geodatabase, create a schema named sde in the database. Set this as the sde user's default schema.
  • If using an sde-schema geodatabase, the sde user must have, at a minimum, the following privileges: CREATE FUNCTION, CREATE PROCEDURE, CREATE TABLE, and CREATE VIEW. For other privileges, see Privileges for geodatabases in SQL Server.

Install clients

The geodatabase administrator can install ArcGIS AllSource (Desktop Standard or Desktop Advanced) or ArcGIS Server (enterprise edition) to create a geodatabase by running a Python script. To run the Enable Enterprise Geodatabase geoprocessing tool instead of a script, install ArcGIS AllSource.

Note:

You need an ArcGIS Server (enterprise edition) keycodes file to authorize your geodatabase in the next section. Even if you do not run a Python script from an ArcGIS Server machine to create the geodatabase, you must install and authorize ArcGIS Server to get the keycodes file. You may need to copy the keycodes file from the ArcGIS Server machine to a location that the Enable Enterprise Geodatabase geoprocessing tool can access.

In most cases, your ArcGIS clients are installed on a different computer than SQL Server. Therefore, you must have a supported SQL Server client installed on the ArcGIS client computer to connect to the database. See ArcGIS system requirements for SQL Server to determine which version SQL Server client you should install to connect to the version of SQL Server you are using.

To connect to SQL Server on a Microsoft Windows machine, you can download the SQL Server client from My Esri or from the Microsoft Download Center. To connect to SQL Server on a Linux machine, download the SQL Server client files from the Microsoft Download Center. Follow the instructions from Microsoft to install the SQL Server client on your client machine.

  1. Install the ArcGIS client you want to use for geodatabase creation.

    Follow the instructions provided in the software installation guides.

  2. Install a SQL Server client on the ArcGIS client computer.

    When you install the SQL Server client on a 64-bit operating system, use the 64-bit SQL Server client executable. If you run the 32-bit SQL Serverclient on a 64-bit operating system, it will fail.

Your ArcGIS client is ready to connect to the database and create a geodatabase. Use one of the methods described in the next section to do this.

Create a geodatabase

The geodatabase administrator can run the Enable Enterprise Geodatabase tool from ArcGIS AllSource (Desktop Standard or Desktop Advanced), or run a Python script from an ArcGIS AllSource (Desktop Standard or Desktop Advanced) or ArcGIS Server (enterprise edition) machine to create a geodatabase in the existing database.

Run the Enable Enterprise Geodatabase tool

You can run the Enable Enterprise Geodatabase tool from ArcGIS AllSource to create a geodatabase in an existing SQL Server database.

Follow these steps to create a geodatabase using the Enable Enterprise Geodatabase tool in ArcGIS AllSource:

  1. Start ArcGIS AllSource.
  2. Connect to the SQL Server database as the geodatabase administrator.

    Save the user's password on the Database Connection dialog box.

  3. Open the Enable Enterprise Geodatabase tool.
  4. Drag your new database connection into the Input Database Connection field.
  5. Browse to the ArcGIS Server authorization file that was created when you authorized ArcGIS Server and add it to the Authorization File text box.

    When you use the wizard to authorize ArcGIS Server, a keycodes file is written to the server where the software is installed. The keycodes file is created in Program Files\ESRI\License<release>\sysgen on Windows servers and /arcgis/server/framework/runtime/.wine/drive_c/Program Files/ESRI/License<release#>/sysgen on Linux servers. Copy the file to a location the Enable Enterprise Geodatabase tool can access. If you have not already done so, authorize ArcGIS Server to create this file.

  6. Click Run.

A geodatabase is created in the database.

Messages related to geodatabase creation are written to the sde_setup.log file, which is created in the directory specified for your %TEMP% variable on the computer where the tool is run. If you have any problems creating a geodatabase, check this file to troubleshoot the problem.

Next, the database administrator can create a user who can load data into the geodatabase.

Run a Python script

To create the geodatabase by running a script from ArcGIS AllSource (Desktop Standard or Desktop Advanced) or ArcGIS Server (enterprise edition) installed on a Windows machine, you can use the script provided here.

Follow these steps to run a Python script to create a geodatabase in an existing SQL Server database:

  1. Create a text file on the ArcGIS client machine and copy the following script into the file:

    """
    Name: enable_enterprise_gdb.py
    Description: Provide connection information to an enterprise database
    and enable enterprise geodatabase.
    Type enable_enterprise_gdb.py -h or enable_enterprise_gdb.py --help for usage
    """
    
    # Import system modules
    import arcpy, os, optparse, sys
    
    
    # Define usage and version
    parser = optparse.OptionParser(usage = "usage: %prog [Options]", version="%prog 1.0 for " + arcpy.GetInstallInfo()['Version'] )
    
    #Define help and options
    parser.add_option ("--DBMS", dest="Database_type", type="choice", choices=['SQL_SERVER', 'ORACLE', 'POSTGRESQL', 'DB2','INFORMIX','DB2ZOS', ''], default="", help="Type of enterprise DBMS:  SQL_SERVER, ORACLE, POSTGRESQL, DB2, INFORMIX, or DB2ZOS.")
    parser.add_option ("-i", dest="Instance", type="string", default="", help="DBMS instance name")
    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="User", type="string", default="", help="Geodatabase administrator user name")
    parser.add_option ("-p", dest="Password", type="string", default="", help="Geodatabase  administrator password")
    parser.add_option ("-D", dest="Database", type="string", default="none", help="Database name:  Not required for Oracle")
    parser.add_option ("-l", dest="Authorization_file", type="string", default="", help="Full path and name of authorization file")
    
    
    # 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
    	account_authentication = options.account_authentication.upper()
    	username = options.User.lower() 
    	password = options.Password	
    	database = options.Database.lower()
    	license = options.Authorization_file
    
    
    	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 (license == ""):
    		print(" \n%s: error: \n%s\n" % (sys.argv[0], "Authorization file (-l) must be specified."))
    		parser.print_help()
    		sys.exit(3)
    
    		
    	# Get the current product license
    	product_license=arcpy.ProductInfo()
    	
    	if (license == ""):
    		print(" \n%s: error: %s\n" % (sys.argv[0], "Authorization file (-l) must be specified."))
    		parser.print_help()
    		sys.exit(3)
    	
    	# Checks required license level
    	if product_license.upper() == "ARCVIEW" or product_license.upper() == 'ENGINE':
    		print("\n" + product_license + " license found!" + "  Enabling enterprise geodatabase functionality requires an ArcGIS Desktop Standard or Advanced, ArcGIS Engine with the Geodatabase Update extension, or ArcGIS Server license.")
    		sys.exit("Re-authorize ArcGIS before enabling an enterprise geodatabase.")
    	else:
    		print("\n" + product_license + " license available!  Continuing to enable...")
    		arcpy.AddMessage("+++++++++")
    	
    	# Local variables
    	instance_temp = instance.replace("\\","_")
    	instance_temp = instance_temp.replace("/","_")
    	instance_temp = instance_temp.replace(":","_")
    	Conn_File_NameT = instance_temp + "_" + database + "_" + username    
    	
    	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)
    	
    	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(out_folder_path=temp, out_name=Connection_File_Name, database_platform=database_type, instance=instance, database=database, account_authentication=account_authentication, username=username, password=password, 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")
    	
    	# Process: Enable geodatabase...
    	try:
    		print("Enabling Enterprise Geodatabase...\n")
    		arcpy.EnableEnterpriseGeodatabase_management(input_database=Connection_File_Name_full_path, authorization_file=license)
    		for i in range(arcpy.GetMessageCount()):
    			arcpy.AddReturnMessage(i)
    		arcpy.AddMessage("+++++++++\n")
    	except:
    		for i in range(arcpy.GetMessageCount()):
    			arcpy.AddReturnMessage(i)
    			
    	if os.path.exists(Connection_File_Name_full_path):
    		os.remove(Connection_File_Name_full_path)
    			
    #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)

  2. Save the file with a .py extension.
  3. Run the script, providing options and information specific to your site.

    In the following example, the file enable_gdb.py is run for database spdata on instance ssprod. The connection is made as the sde login with password Tgdbst@rtsh3r3. A keycodes file in the default ArcGIS Server location is specified to authorize the geodatabase.

    enable_gdb.py --DBMS SQL_SERVER -i ssprod --auth DATABASE_AUTH 
    -u sde -p Tgdbst@rtsh3r3 -D spdata -l '\\Program Files\ESRI\License\sysgen\keycodes'
    Tip:

    Type -h or --help at the command prompt to get syntax help.

You now have a geodatabase in the SQL Server database.

A log file for the geodatabase creation (GDBCreateGeodatabase<#>.log) is written to the directory specified for your %TEMP% variable on the computer where the script is run.

Next, the database administrator can create a user who can load data into the geodatabase.