remote connection question

558
6
10-15-2019 08:09 PM
lmzh
by
New Contributor

I want to connect a remote sever via python code ,my code is :

arcpy.env.workspace = r"Database Connections\Connection to 10.246.146.120.sde"
wk = r"Database Connections\Connection to 10.246.146.120.sde"

def list_feature_batch1(pathsde):

    env.workspace = pathsde
    # print arcpy.env.workspace
    datasets = arcpy.ListDatasets()
    datasets = [''] + datasets if datasets is not None else []
    #print datasets
    wklst = []
    for ds in datasets:
        # print ds
        # env.workspace = env.workspace + os.sep + ds
        wk = env.workspace + os.sep + ds
        # print env.workspace
        wklst.append(wk)
    return wklst

# print arcpy.env.workspace
# database = 'Database Connections\\Connection to 10.246.146.120.sde'
# versions = arcpy.ListVersions(database)
for dataset in list_feature_batch1(wk):
print dataset
......
list_feature_batch1 is a function,it works well.

why doesnot the code work,but when I add code that arcpy.env.workspace = r"Database Connections\Connection to 127.0.0.1.sde
the code can run correctly.
0 Kudos
6 Replies
JoshuaBixby
MVP Esteemed Contributor

It is difficult to comment on what might be happening when the core of the issue seems to revolve around the list_feature_batch1 code, and none of that code is provided.

0 Kudos
lmzh
by
New Contributor
def list_feature_batch1(pathsde):

    env.workspace = pathsde
    # print arcpy.env.workspace
    datasets = arcpy.ListDatasets()
    datasets = [''] + datasets if datasets is not None else []
    #print datasets
    wklst = []
    for ds in datasets:
        # print ds
        # env.workspace = env.workspace + os.sep + ds
        wk = env.workspace + os.sep + ds
        # print env.workspace
        wklst.append(wk)
    return wklst
0 Kudos
JakeSkinner
Esri Esteemed Contributor

Hi lm zh,

A requirement for serveral list functions is for the environment to be set first (i.e. using arcpy.env.workspace).  See the following link:

ListFeatureClasses—ArcPy Functions | ArcGIS Desktop 

0 Kudos
lmzh
by
New Contributor

Thanks your reply. I set  workspace as following: arcpy.env.workspace =r"Database Connections\Connection to 10.246.146.120.sde" first, but running code has not result. however,adding the code which is

arcpy.env.workspace = r"Database Connections\Connection to 127.0.0.1.sde,the entire code can work correctly.why?

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Does the SDE connection file with 10. in the name work if you use it in ArcCatalog?

0 Kudos
lmzh
by
New Contributor

I connect sde file with arcmap10.6.1,datebase is oracle11g

0 Kudos