Cannot open workspace

2905
8
01-25-2017 12:23 PM
by Anonymous User
Not applicable

FIXED THE SCRIPT COPY/PASTE below:

HI all -

Maybe you can help me out.

I've been getting this error for ages and it is making me nuts:

Here's the script:

# Move points based up current lat/lon
#grab stuff you need
import arcpy, os


# Set variables
folderName = r"S:\AGR\AGR-Shared\AGR-GIS\AGR_Data"
fileName = "Connection to cloud.agriculture.vermont.gov.sde"
filepath = r'S:\AGR\AGR-Shared\AGR-GIS\AGR_Data\Connection to cloud.agriculture.vermont.gov.sde'
serverName = "agr-ofwq2012\AGRGIS"
serviceName = "5151"
databaseName = "AGRGISDATA"
authType = "DATABASE_AUTH"
username = "**********"
password = "**********"
saveUserInfo = "SAVE_USERNAME"
versionName = "SDE.DEFAULT"
saveVersionInfo = "SAVE_VERSION"

# Process: Use the CreateArcSDEConnectionFile function
arcpy.CreateDatabaseConnection_management(folderName,
                                          fileName,
                                          "SQL_SERVER",
                                          serverName,
                                          authType,
                                          username,
                                          password,
                                          saveUserInfo,
                                          databaseName)

fc = "AGRGISDATA.DBO.ApiariesWGS"
print fc
fc_path = os.path.join(filepath, fc)
print fc_path
fields = ['Longtitude','Latitude','SHAPE@XY']
print fields
arcpy.env.workspace = filepath
workspace = os.path.dirname(filepath)
print workspace
editor = arcpy.da.Editor(workspace)
print editor
editor.startEditing(False, False)
editor.startOperation()

#create curser on fc
try:
     with arcpy.da.UpdateCursor(fc,fields) as cursor:
          for row in cursor:
               x = row[0]
               y = row[1]
               xy = (x,y)
               pnt = xy
               row[2] = pnt
               cursor.updateRow(row)
finally:
     editor.stopEditing(True)
     del editor
Tags (2)
0 Kudos
8 Replies
DanPatterson_Retired
MVP Emeritus

is you line 17 and 18 a copy paste format glitch? it seems to be a concatenation of a comment and another line

0 Kudos
by Anonymous User
Not applicable

yeah, this is a copy/paste weirdness

0 Kudos
DarrenWiens2
MVP Honored Contributor

Is this the exact code that caused the error? I don't see any reason why Line 35 (pnt = xy) should be trying to access any workspace at all. Also, Line 1 should have a syntax error (the character before the comment) and Line 39 should be 'editor' not 'edit'.

edit: I see that your current Line 18 should be split across several lines, which is messing up your Line numbering. What is supposed to be Line 35?

0 Kudos
RandyBurton
MVP Alum

I think line 35 is actually line 23 in the original code (as both lines 1 and 18 are multiple lines):

arcpy.env.workspace = filepath‍
0 Kudos
curtvprice
MVP Esteemed Contributor

So, your workspace definition is invalid. There could be several reasons for that, but for starters, spaces in pathnames are never a good idea. In fact anything outside [a..z][0..9]_ should be avoided.

0 Kudos
DanPatterson_Retired
MVP Emeritus

once that is solved... it will be time to move on to how the coordinates are collected and which are the actual coordinates (I would check field name spelling first).  Another reason to work on a local drive, then upload results.

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

Besides the comments above, I don't see where you mention the version you are using.  Did it break after upgrading ArcGIS Server?  Using a service like 5151 is not available in the current versions and you you may benefit from switching this to a Direct Connect.

Why should I be making direct connections to an ArcSDE geodatabase? | ArcGIS Blog 

That is an older blog, but might get you headed in the right direction with Direct Connects.

0 Kudos
JonathanQuinn
Esri Notable Contributor

This does seem like a pathing issue:

folderName = r"S:\AGR\AGR-Shared\AGR-GIS\AGR_Data"
fileName = "Connection to cloud.agriculture.vermont.gov.sde"
filepath = r'S:\AGR\AGR-Shared\AGR-GIS\AGR_Data\AutoConnection to cloud.agriculture.vermont.gov.sde'

The full file path in the filePath variable has an "Auto" in it, which seems out of place given your folderName and fileName variables.

0 Kudos