def _get_ent_db(self): ''' creates an arcpy db connection file. Inputs are from esri documentation''' if self.properties["remove_existing"]: ## remove any old connection files self._check_existing() try: connection = arcpy.CreateDatabaseConnection_management( self.properties["folder_path"], self.properties["name"], self.properties["database_platform"], self.properties["instance"], self.properties["account_authentication"], self.properties["username"], self.properties["password"], self.properties["save_user_pass"], self.properties["database"], self.properties["schema"], self.properties["version_type"], self.properties["version"], self.properties["date"]) except Exception as e: self.logger.error("failed to create connection file") self.logger.debug(e) raise Exception("failed to create connection file") else: self.logger.debug("keeping existing database connection") return os.path.join(self.properties["folder_path"], self.properties["name"])
def PrepFCs(sSDEconn): sDatabase = "db_7ifhn" sUser = "******" sUser2 = "hsu_3yd5x" sPassword = "******" if os.path.exists(sSDEconn) == False: arcpy.CreateDatabaseConnection_management( os.path.split(sSDEconn)[0], os.path.split(sSDEconn)[1], "POSTGRESQL", "localhost,9876", "DATABASE_AUTH", sUser, sPassword, "SAVE_USERNAME", sDatabase) return os.path.join( sSDEconn, ".".join([sDatabase, sUser2, "template_oilmap_SpillPoint"])), os.path.join( sSDEconn, ".".join([sDatabase, sUser2, "template_oilmap_ShoreOil"])), os.path.join( sSDEconn, ".".join([ sDatabase, sUser2, "template_oilmap_Spillets" ])), os.path.join( sSDEconn, ".".join([ sDatabase, sUser2, "template_oilmap_Trackline" ])), os.path.join( sSDEconn, ".".join([ sDatabase, sUser2, "template_oilmap_Thickness" ]))
def createTmpConnection(work, tempConnect): # ------------------------------------------------------------- # connection parameters usr = "******" # oracle user name pw = "supMego8612" # oracle password (enter correct password for user before running # pw = getpass.getpass() database_platform = "ORACLE" instance = "bcgw.bcgov/idwprod1.bcgov" authentication = "DATABASE_AUTH" # create a temporary connection file print work + os.sep + tempConnect if arcpy.Exists(work + tempConnect + ".sde"): arcpy.AddMessage("Temp BCGW connection already exists: ignore create") else: print usr, pw, database_platform, instance, authentication arcpy.AddMessage("Creating connection...") arcpy.CreateDatabaseConnection_management( # revised connection method 2017 work, # folder to create the connection tempConnect, # name of connection database_platform, # database_platform (Oracle) instance, # instance authentication, # authentication usr, # username pw # password )
def get_db_conn(server, database, version='sde.DEFAULT'): """ Creates a sde connection in the scratch folder and returns the path to `.sde` file. Assumes OSA, and a SQL Server database. Parameters: ------------ server: str Database server/instance database: str Name of the database Returns: -------- string with full path to the `.sde` file """ scratch_work = arcpy.env.scratchFolder conn_name = 'temp__{}_{}'.format(server, database) conn_path = '{}//{}.sde'.format(scratch_work, conn_name) with TempOverwrite(): arcpy.CreateDatabaseConnection_management( scratch_work, conn_name, database_platform='SQL_SERVER', instance=server, account_authentication='OPERATING_SYSTEM_AUTH', database=database, version=version) return conn_path
def conectionGDB_arcpy(ip="172.18.1.93"): if arcpy.Exists("CPV_SEGMENTACION.sde") == False: arcpy.CreateDatabaseConnection_management( "Database Connections", 'CPV_SEGMENTACION.sde', 'SQL_SERVER', ip, 'DATABASE_AUTH', 'sde', "$deDEs4Rr0lLo", "#", 'GEODB_CPV_SEGM', "#", '#', '#', "#") conexionGDB = r'Database Connections\CPV_SEGMENTACION_GDB.sde' return conexionGDB
def conexion_arcgis(db, ip_server, usuario, password): if arcpy.Exists("{}.sde".format(db)) == False: arcpy.CreateDatabaseConnection_management( "Database Connections", "{}.sde".format(db), "SQL_SERVER", ip_server, "DATABASE_AUTH", usuario, password, "#", "{}".format(db), "#", "#", "#", "#") path_conexion = "Database Connections/{}.sde".format(db) return path_conexion
def conectionDB_arcpy(ip, nombre): if arcpy.Exists("{}.sde".format(nombre)) == False: arcpy.CreateDatabaseConnection_management( "Database Connections", "{}.sde".format(nombre), "SQL_SERVER", ip, "DATABASE_AUTH", "us_arcgis_seg_2", "MBs0p0rt301", "#", nombre, "#", "#", "#", "#") conexionDB = r'Database Connections\{}.sde'.format(nombre) return conexionDB
def createDBConnectionFile(instance, database_type, database, account_authentication, dbms_admin, dbms_admin_pwd): # 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: arcpy.AddMessage("Creating Database Connection File...") # Process: Create Database Connection File... # Usage: out_file_location, out_file_name, DBMS_TYPE, instnace, account_authentication, username, password, database, 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=dbms_admin, password=dbms_admin_pwd, save_user_pass="******") for i in range(arcpy.GetMessageCount()): if "000565" in arcpy.GetMessage( i): # Check if database connection was successful arcpy.AddReturnMessage(i) arcpy.AddMessage("++++++++++++++++++") arcpy.AddMessage("Exiting!!") arcpy.AddMessage("++++++++++++++++++") sys.exit(3) else: arcpy.AddReturnMessage(i) arcpy.AddMessage("++++++++++++++++++") except: for i in range(arcpy.GetMessageCount()): arcpy.AddReturnMessage(i) connection = Connection_File_Name_full_path return connection
def connect_arcpy(): if arcpy.Exists(r"Database Connections\{}.sde".format( config.DB_NAME)) == False: arcpy.CreateDatabaseConnection_management( "Database Connections", "{}.sde".format(config.DB_NAME), "SQL_SERVER", config.HOST, "DATABASE_AUTH", config.USER, config.PASSWORD, "#", "{}".format(config.DB_NAME), "#", "#", "#", "#") path_conexion = r"Database Connections\{}.sde".format(config.DB_NAME) return path_conexion
def connsde(configkey): #delete connection deleteconn(configkey) #arcpy create connection arcpy.CreateDatabaseConnection_management( configkey['out_folder_path'], configkey['out_name'], configkey['database_platform'], configkey['instance'], configkey['account_authentication'], configkey['username'], configkey['password'], configkey['save_user_pass'], configkey['database'], configkey['schema'], configkey['version_type'], configkey['version'], configkey['date'])
def createUserConnectionFiles(instance, database_type, database, account_authentication, role, dbuser_pwd, out_folder_path): # Local variables if role == 'sde': dbuser_name = 'SDE' else: dbuser_name = database.upper() + '_' + role.upper() # if dbuser_pwd != '#': # dbuser_pwd = database.lower() + '_' + role.upper() + '_' + str(datetime.datetime.now().year) # arcpy.AddMessage(dbuser_pwd) instance_temp = instance.replace("\\", "_") instance_temp = instance_temp.replace("/", "_") instance_temp = instance_temp.replace(":", "_") Conn_File_NameT = instance_temp + "." + database + "." + dbuser_name Connection_File_Name = Conn_File_NameT + ".sde" Connection_File_Name_full_path = out_folder_path + 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: arcpy.AddMessage("Creating Database Connection File...") # Process: Create Database Connection File... # Usage: out_file_location, out_file_name, DBMS_TYPE, instnace, account_authentication, username, password, database, save_username_password(must be true) arcpy.CreateDatabaseConnection_management( out_folder_path=out_folder_path, out_name=Connection_File_Name, database_platform=database_type, instance=instance, database=database, account_authentication=account_authentication, username=dbuser_name, password=dbuser_pwd, save_user_pass="******") for i in range(arcpy.GetMessageCount()): if "000565" in arcpy.GetMessage( i): # Check if database connection was successful arcpy.AddReturnMessage(i) arcpy.AddMessage("++++++++++++++++++") arcpy.AddMessage("Exiting!!") arcpy.AddMessage("++++++++++++++++++") sys.exit(3) else: arcpy.AddReturnMessage(i) arcpy.AddMessage("++++++++++++++++++") except: for i in range(arcpy.GetMessageCount()): arcpy.AddReturnMessage(i) return Connection_File_Name_full_path
def conectionDB_arcpy(): if arcpy.Exists("{}.sde".format(DB_NAME)) == False: arcpy.CreateDatabaseConnection_management("Database Connections", "{}.sde".format(DB_NAME), "SQL_SERVER", HOST, "DATABASE_AUTH", USER, PASSWORD, "#", DB_NAME, "#", "#", "#", "#") conexionDB = r'Database Connections\{}.sde'.format(DB_NAME) return conexionDB
def createSdeConnection(connectionName, username, password): # Set variables fileName = connectionName + ".sde" serverName = str(sys.argv[1]) # HOST instance = str(sys.argv[2]) # oracle SID/service name authType = "DATABASE_AUTH" saveUserInfo = "SAVE_USERNAME" arcpy.CreateDatabaseConnection_management(folderName, fileName, "ORACLE", serverName + "/" + instance, authType, username, password, saveUserInfo)
def create_db_connection(self): arcpy.CreateDatabaseConnection_management( self.__CONNECTION["path"], self.__CONNECTION["name"], self.__CONNECTION["platform"], self.__CONNECTION["instance"], self.__CONNECTION["auth"], self.__CONNECTION["username"], self.__CONNECTION["password"], self.__CONNECTION["saveUserInfo"], self.__CONNECTION["databaseName"], self.__CONNECTION["versionName"], self.__CONNECTION["saveVersionInfo"])
def InsertarRegistros(self): arcpy.env.workspace = "Database Connections/PruebaSegmentacion.sde" arcpy.env.outputCoordinateSystem = arcpy.SpatialReference(4326) if arcpy.Exists("GEODATABASE.sde") == False: arcpy.CreateDatabaseConnection_management( "Database Connections", "GEODATABASE.sde", "SQL_SERVER", self.server, "DATABASE_AUTH", "sde", "$deDEs4Rr0lLo", "#", "GEODB_CPV_SEGM", "#", "#", "#", "#") arcpy.env.workspace = "Database Connections/GEODATABASE.sde" path_conexion2 = "Database Connections/GEODATABASE.sde" segm_ruta_prueba = path_conexion2 + "/GEODB_CPV_SEGM.SDE.SEGM_RUTA_PRUEBA" segm_aeu_prueba = path_conexion2 + "/GEODB_CPV_SEGM.SDE.SEGM_AEU_PRUEBA" list_capas = [[self.tb_rutas, segm_ruta_prueba], [self.tb_aeus, segm_aeu_prueba]] i = 0 data = [] for x in arcpy.da.SearchCursor(self.tb_zonas, ["UBIGEO", "ZONA", "ID_ESTRATO"]): if int(x[2]) == 1: data.append([ x[0], x[1], self.cant_viv_techo_gra_ciud, self.techo_segunda_pasada_gra_ciud, self.uso_falso_cod ]) else: data.append([ x[0], x[1], self.cant_viv_techo_peq_ciud, self.techo_segunda_pasada_peq_ciud, self.uso_falso_cod ]) where_final = expresiones_consulta_arcpy.Expresion_2( data, [['UBIGEO', 'TEXT'], ['ZONA', 'TEXT'], ['TECHO', 'SHORT'], ['TECHO_S_P', 'SHORT'], ['FALSO_COD', 'SHORT']]) print where_final for el in list_capas: i = i + 1 #a = arcpy.MakeTableView_management(el[1], "a{}".format(i), "({}) and TECHO={}".format(self.where_expression,self.cant_viv_techo_gra_ciud)) a = arcpy.MakeTableView_management(el[1], "a{}".format(i), where_final) #print int(arcpy.GetCount_management(a).getOutput(0)) if (int(arcpy.GetCount_management(a).getOutput(0)) > 0): arcpy.DeleteRows_management(a) #b = arcpy.MakeTableView_management(el[0], "b{}".format(i), "({}) and TECHO={}".format(self.where_expression,self.cant_viv_techo_gra_ciud) ) b = arcpy.MakeTableView_management(el[0], "b{}".format(i), where_final) arcpy.Append_management(b, el[1], "NO_TEST")
def doCreateFile(self,pCombox): out_name=self.strfileName.get() #sde文件的名称 if(out_name is None): tkMessageBox.showinfo("error","请输入sde文件名") return instance=self.strInstance.get() if(instance is None): tkMessageBox.showinfo("error","请输入sde文件名") return username=self.strUserName.get() password=self.strPassword.get() # database=pCombox.get() file_output_folder=os.path.split(self.save_path.get())[0] out_name=os.path.split(self.save_path.get())[1] if(database=="SqlServer"): db=self.strDataBase.get() result=arcpy.CreateDatabaseConnection_management(file_output_folder,out_name,"SQL_SERVER",instance,"DATABASE_AUTH",username, password, "SAVE_USERNAME",db) else: result=arcpy.CreateDatabaseConnection_management(file_output_folder,out_name,"ORACLE",instance,"DATABASE_AUTH",username, password, "SAVE_USERNAME") tkMessageBox.showinfo("info","创建成功")
def createConnFile(self): ''' Turns out this is actually much simpler than was originally thought. Don't need a schema or a password to create the the sde file. This makes things much simpler ''' # connFileFullPath = self.secrets.getConnectionFilePath() connDirPath, connFilePath = os.path.split(self.connFile2Create) self.logger.debug("connDir: %s", connDirPath) self.logger.debug("connFile: %s", connFilePath) self.logger.debug("Connection file: %s", self.connFile2Create) suffix = os.path.splitext(self.connFile2Create)[1] if not suffix: self.connFile2Create = '{0}.sde'.format(self.connFile2Create) if not os.path.exists(self.connFile2Create): # if not arcpy.Exists(connFileFullPath): self.logger.debug('trying to create conn file ...') # for direct connect use: # CreateDatabaseConnection_management # host:port/serviceName, most of the time its just host/serviceName connStr = self.getConnectionString() self.logger.debug("importing arcpy...") import arcpy # @UnresolvedImport self.logger.debug("arcpy imported") arcpy.SetProduct('arcinfo') self.logger.debug('arcpy product info %s', arcpy.ProductInfo()) self.logger.debug("arcpytool report: %s", arcpy.CreateDatabaseConnection_management) self.logger.debug( 'inspect %s', inspect.getargspec(arcpy.CreateDatabaseConnection_management)) # seems to require a value for username and password even through they are invalid arcpy.CreateDatabaseConnection_management(connDirPath, connFilePath, self.dbtype.upper(), connStr, 'DATABASE_AUTH', 'junk', 'junk', 'DO_NOT_SAVE_USERNAME', self.sde) self.logger.info('connection file %s has been created', self.connFile2Create)
def __init__(self): """Define the tool (tool name is the name of the class).""" self.label = "UpdateOverlapReportConfig" self.description = "" self.canRunInBackground = False # load config self._config = JSONConfig(class_name="OverlapReport") # get UI ready for update - let users select related tables file_name = TempFileName.generate_temporary_file_name(".sde", True) arcpy.CreateDatabaseConnection_management( TempFileName.get_temp_directory(), file_name, "SQL_SERVER", self._config.instance, "OPERATING_SYSTEM_AUTH", "", "", "", self._config.database) self._connection_file = f"{TempFileName.get_temp_directory()}/{file_name}" super(UpdateOverlapReportConfig, self).__init__()
def CreateBCGWConn(dbUser, dbPass): connBCGW = os.path.join(os.path.dirname(arcpy.env.scratchGDB), 'BooBuffer.sde') if os.path.isfile(connBCGW): os.remove(connBCGW) try: arcpy.CreateDatabaseConnection_management(os.path.dirname(connBCGW), os.path.basename(connBCGW), 'ORACLE', connInstance, username=dbUser, password=dbPass) except: print 'Error Creating BCGW connection....' connBCGW = None return connBCGW
def makeConnection(authenticationType, pathParent): #Creates connection file so code can edit .sde database #make this work when r"U:\tempstuff" already exists outFolderPath = pathParent outName = r"actualName" + str(button2.databaseX) + r".sde" databasePlatform = "SQL_Server" instance = button2.instanceX database = button2.databaseX username = "******" #doesn't seem to matter password = "******" #doesn't seem to matter version = button2.currentVersion arcpy.CreateDatabaseConnection_management( outFolderPath, outName, databasePlatform, instance, authenticationType, username, password, 'DO_NOT_SAVE_USERNAME', database, '', 'TRANSACTIONAL', version, '')
def DBConns(): #schemae is a list of the connection strings for the database owner user/password. The db owner should match the first part of the DBC connection name.sde variable schemae = ["redacted"] for schema in schemae: pwd = schema.split(" ")[1] usr = schema.split(" ")[0] #this is the user name #print usr #this is the password #print pwd dbname = usr + ".sde" arcpy.env.overwriteOutput = 1 #this .sde file goes your APPDATA roaming ESRI database connections arcpy.CreateDatabaseConnection_management("Database Connections", dbname, "ORACLE", "SDETEST", "DATABASE_AUTH", usr, pwd)
def createEGDBConnectionFile(): print("Creating connection file in the local directory") out_folder_path = "." out_name = "sa_connection_to_edmar_test" database_platform = "SQL_SERVER" instance = "localhost" account_authentication = "DATABASE_AUTH" username = "******" password = "******" save_user_pass = "******" database = "edmar_test" arcpy.CreateDatabaseConnection_management(out_folder_path, out_name, database_platform, instance, account_authentication, username, password, save_user_pass, database)
def PrepFCs(sSDEconn): sDatabase = "db_ckn82" sUser = "******" sUser2 = "hsu_4p3wv" sPassword = "******" if os.path.exists(sSDEconn) == False: arcpy.CreateDatabaseConnection_management( os.path.split(sSDEconn)[0], os.path.split(sSDEconn)[1], "POSTGRESQL", "localhost,9876", "DATABASE_AUTH", sUser, sPassword, "SAVE_USERNAME", sDatabase) return os.path.join(sSDEconn, ".".join([ sDatabase, sUser2, "spillets_1" ])), os.path.join(sSDEconn, ".".join([ sDatabase, sUser2, "trackline_1" ])), os.path.join(sSDEconn, ".".join([sDatabase, sUser2, "thickness_1"]))
def CreateBCGWConn(dbUser, dbPass): connBCGW = os.path.join(os.path.dirname(arcpy.env.scratchGDB), 'RdClass_BCGW.sde') if os.path.isfile(connBCGW): os.remove(connBCGW) #print "Creating new BCGW Connection File..." #connInstance = r'bcgw.bcgov/idwprod1.bcgov' try: arcpy.CreateDatabaseConnection_management(os.path.dirname(connBCGW), os.path.basename(connBCGW), 'ORACLE', connInstance, username=dbUser, password=dbPass) except: print 'Error Creating BCGW connection....' connBCGW = None return connBCGW
def create_enterprise_GDB(self, gdb_name, host, dba, dbapass, sdeuser, sdepass, keycode): # gdb_name = country.lower()+'_'+product #print(gdb_name) arcpy.CreateEnterpriseGeodatabase_management("PostgreSQL", host, gdb_name, "DATABASE_AUTH", dba, dbapass, "SDE_SCHEMA", sdeuser, sdepass, "", keycode) logging.debug("Enterprise Geodatabase {0} is created".format(gdb_name)) arcpy.CreateDatabaseConnection_management( "Database Connections", "{0}.sde".format(gdb_name), "POSTGRESQL", host, "DATABASE_AUTH", sdeuser, sdepass, "SAVE_USERNAME", gdb_name, "#", "POINT_IN_TIME", "#", "5/19/2017 8:43:41 AM") logger.debug( "Database connection for geodatabase {0} is created".format( gdb_name)) return None
def ARCGIS_create_database(gdbpath, time_ymdhms, datatype): SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) authorization_file = os.path.join(SCRIPT_DIR, u"server10.2.ecp") database_name = datatype + time_ymdhms arcpy.CreateEnterpriseGeodatabase_management( database_platform=u"PostgreSQL", instance_name=u"localhost", database_name=database_name, account_authentication=u"DATABASE_AUTH", database_admin=u"postgres", database_admin_password=u"Lantucx2018", sde_schema=u"SDE_SCHEMA", gdb_admin_name=u"sde", gdb_admin_password=u"sde", tablespace_name=u"#", authorization_file=authorization_file) connsdepath = SCRIPT_DIR connsde = database_name + u".sde" conn = {} conn[u"out_folder_path"] = connsdepath conn[u"out_name"] = connsde conn[u"database_platform"] = u"PostgreSQL" conn[u"instance"] = u"localhost" conn[u"account_authentication"] = u"DATABASE_AUTH" conn[u"database"] = database_name conn[u"username"] = u"sde" conn[u"password"] = u"sde" conn[u"save_user_pass"] = u"SAVE_USERNAME" arcpy.CreateDatabaseConnection_management(**conn) arcpy.env.workspace = gdbpath sdepath = os.path.join(SCRIPT_DIR, connsde) for ds in arcpy.ListDatasets(feature_type=u'feature') + [u'']: if ds != u'': dspath = os.path.join(gdbpath, ds) sdedspath = os.path.join(sdepath, ds) arcpy.Copy_management(dspath, sdedspath) else: for fc in arcpy.ListFeatureClasses(feature_dataset=ds): fcpath = os.path.join(gdbpath, ds, fc) sdedspath = os.path.join(sdepath, ds, fc) arcpy.Copy_management(fcpath, sdedspath) print u'创建空间库成功' return datatype + time_ymdhms + ".sde"
def conectionGDB_Monitoreo(): ip = '192.168.202.84' if arcpy.Exists("CPV_MONITOREO_GIS.sde") == False: arcpy.CreateDatabaseConnection_management("Database Connections", "CPV_MONITOREO_GIS.sde", "SQL_SERVER", ip, "DATABASE_AUTH", "sde", "wruvA7a*tat*", "#", "CPV_MONITOREO_GIS", "#", "#", "#", "#") conexionDB = r'Database Connections\{}.sde'.format("CPV_MONITOREO_GIS") return conexionDB
def CreateSDE_Version(): '''This is to make sure that the version exists before the script runs''' print("Checking SDE connections.\n") sdeTempPath = tempfile.mkdtemp() arcpy.CreateDatabaseConnection_management(sdeTempPath, "Editor.sde", "SQL_SERVER", SERVERNAME, "OPERATING_SYSTEM_AUTH") sdeVersionNameFULL = "" sdeVersionLIST = [] for version in arcpy.da.ListVersions(sdeTempPath + os.sep + "Editor.sde"): sdeVersionNameFULL = version.name.split(".")[0] sdeVersionLIST.append(sdeVersionNameFULL) if sdeVersionNameFULL == '"MCKINNEY\\JCARMONA"': if version.description == "": arcpy.AlterVersion_management(sdeTempPath + os.sep + "Editor.sde", '"MCKINNEY\JCARMONA".CARMONA', description = "[email protected] | ext 7422") #print(sdeVersionLIST) if '"MCKINNEY\\JCARMONA"' not in sdeVersionLIST: print("\tCARMONA version not found, creating now.") arcpy.CreateVersion_management(sdeTempPath + os.sep + "Editor.sde", "sde.DEFAULT" ,"CARMONA", "PUBLIC") arcpy.AlterVersion_management(sdeTempPath + os.sep + "Editor.sde", '"MCKINNEY\JCARMONA".CARMONA', description = "[email protected] | ext 7422") print("Version created.") shutil.rmtree(sdeTempPath)
def PrepFCs(sSDEconn): sDatabase = "db_qdrdy" sUser = "******" sUser2 = "hsu_kepzo" sPassword = "******" if os.path.exists(sSDEconn) == False: arcpy.CreateDatabaseConnection_management( os.path.split(sSDEconn)[0], os.path.split(sSDEconn)[1], "POSTGRESQL", "localhost,9876", "DATABASE_AUTH", sUser, sPassword, "SAVE_USERNAME", sDatabase) # change these tables according to postgres tables return os.path.join(sSDEconn, ".".join( [sDatabase, sUser2, "PARTICLES"])), os.path.join( sSDEconn, ".".join([sDatabase, sUser2, "TRACKLINE"])), os.path.join( sSDEconn, ".".join([sDatabase, sUser2, "ABCDBOX"])), os.path.join( sSDEconn, ".".join([sDatabase, sUser2, "ABCDPOINTS"])), os.path.join( sSDEconn, ".".join([sDatabase, sUser2, "SEARCHAREA"]))
def CreateBCGWConn(dbUser, dbPass, dbInstance='Prod'): connBCGW = os.path.join( os.path.dirname(gp.env.scratchGDB), 'BCGW_Metadata_TSBExtract_{0}_temp.sde'.format(dbInstance)) if os.path.isfile(connBCGW): os.remove(connBCGW) print "Creating new BCGW-{0} Connection File...".format(dbInstance) if dbInstance == 'Prod': connInstance = r'bcgw.bcgov/idwprod1.bcgov' elif dbInstance == 'Test': connInstance = r'bcgw-i.bcgov/idwtest1.bcgov' elif dbInstance == 'Delivery': connInstance = r'bcgw-i.bcgov/idwdlvr1.bcgov' try: gp.CreateDatabaseConnection_management(os.path.dirname(connBCGW), os.path.basename(connBCGW), 'ORACLE', connInstance, username=dbUser, password=dbPass) except: print 'Error Creating BCGW-{0} connection....'.format(dbInstance) connBCGW = None return connBCGW