I updated to ArcPro 2.6 (python 3.6.10) and after I noticed that one of my tools/scrips now giving the following error. I am assuming something from the ArcPro 2.6 python 3.6.10 is now throwing it off but I am not sure what. I did not change any of the code. I tried change workspace to from r"Database Connections\Connection to Blah" to " C:\Users\***\AppData\Roaming\ESRI\Desktop10.6\ArcCatalog\***.gds" but that didn't work. Can someone shine in as to why the code is failing after the upgrade to ArcPro 2.6?
The database is in a ArcSDE Personal SQL Server
ERROR 000464: Cannot get exclusive schema lock. Either being edited or in use by another application.
Failed to execute (CopyFeatures).
<SPAN class="keyword token">import</SPAN> arcpy<SPAN class="punctuation token">,</SPAN> os
<SPAN class="keyword token">from</SPAN> arcpy <SPAN class="keyword token">import</SPAN> env
fc <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Blah.DBO.Blah"</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"Database Connections\Connection to Blah"</SPAN>
pointLayer <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">+</SPAN> os<SPAN class="punctuation token">.</SPAN>sep <SPAN class="operator token">+</SPAN> <SPAN class="string token">"Blah"</SPAN> <SPAN class="comment token">#target point feature class </SPAN>
<SPAN class="comment token"># Start an edit session. Must provide the worksapce.</SPAN>
edit <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>Editor<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Edit session is started without an undo/redo stack for versioned data</SPAN>
<SPAN class="comment token"># (for second argument, use False for unversioned data)</SPAN>
edit<SPAN class="punctuation token">.</SPAN>startEditing<SPAN class="punctuation token">(</SPAN><SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Start an edit operation</SPAN>
edit<SPAN class="punctuation token">.</SPAN>startOperation<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
input <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN>
Range <SPAN class="operator token">=</SPAN> float<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Create empty Point and Array objects</SPAN>
point <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
array <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># A list that will hold each the Polyline object</SPAN>
featureList <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN>
rows <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>input<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> rows<SPAN class="punctuation token">:</SPAN>
geom <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">.</SPAN>Shape
point<SPAN class="punctuation token">.</SPAN>X <SPAN class="operator token">=</SPAN> geom<SPAN class="punctuation token">.</SPAN>centroid<SPAN class="punctuation token">.</SPAN>X
point<SPAN class="punctuation token">.</SPAN>Y <SPAN class="operator token">=</SPAN> geom<SPAN class="punctuation token">.</SPAN>centroid<SPAN class="punctuation token">.</SPAN>Y
<SPAN class="comment token"># Add each point to the array</SPAN>
array<SPAN class="punctuation token">.</SPAN>add<SPAN class="punctuation token">(</SPAN>point<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Create the polyline</SPAN>
polyline <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Polyline<SPAN class="punctuation token">(</SPAN>array<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Clear the array for future use</SPAN>
array<SPAN class="punctuation token">.</SPAN>removeAll<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
featureList<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>polyline<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">del</SPAN> row<SPAN class="punctuation token">,</SPAN> rows
<SPAN class="comment token"># Copy the polyline to file geodatabase to create a Shape_Length field</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CopyFeatures_management<SPAN class="punctuation token">(</SPAN>featureList<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"line_test"</SPAN><SPAN class="punctuation token">)</SPAN>
rows <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"line_test"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> rows<SPAN class="punctuation token">:</SPAN>
geom <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">.</SPAN>shape
X <SPAN class="operator token">=</SPAN> geom<SPAN class="punctuation token">.</SPAN>lastPoint<SPAN class="punctuation token">.</SPAN>X
Y <SPAN class="operator token">=</SPAN> geom<SPAN class="punctuation token">.</SPAN>lastPoint<SPAN class="punctuation token">.</SPAN>Y
length <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">.</SPAN>Shape_Length <SPAN class="operator token">/</SPAN> <SPAN class="number token">5.28</SPAN> <SPAN class="operator token">+</SPAN> Range
<SPAN class="keyword token">del</SPAN> row<SPAN class="punctuation token">,</SPAN> rows
row_value <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>length<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">(</SPAN>X<SPAN class="punctuation token">,</SPAN> Y<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
cursor <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>InsertCursor<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"SiteNum"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"SHAPE@XY"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
cursor<SPAN class="punctuation token">.</SPAN>insertRow<SPAN class="punctuation token">(</SPAN>row_value<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#arcpy.Delete_management("line_test")</SPAN>
<SPAN class="comment token"># Stop the edit operation.</SPAN>
edit<SPAN class="punctuation token">.</SPAN>stopOperation<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Stop the edit session and save the changes</SPAN>
edit<SPAN class="punctuation token">.</SPAN>stopEditing<SPAN class="punctuation token">(</SPAN><SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>RefreshActiveView<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>I did try to add a create database connection but I get the following error.
edit = arcpy.da.Editor(arcpy.env.workspace)
RuntimeError: cannot open workspace
arcpy.env.overwriteOutput = True
out_folder_path = r"C:\Temp"
out_name = "Connect.sde"
platform = "SQL_SERVER"
instance = "SQL_SERVER"
database = r"Database Servers\***.gds\blah (VERSION:dbo.DEFAULT)"
arcpy.CreateDatabaseConnection_management(out_folder_path,
out_name,
platform,
instance,
"OPERATING_SYSTEM_AUTH",
"#",
"#",
"#",
database)
print(out_name)
workspace = os.path.join(out_folder_path, out_name +".sde")
# Set the workspace environment
arcpy.env.workspace = workspace
print(workspace)
fc = "Blah.DBO.Blah"
arcpy.env.workspace = r"Database Connections\Connection to Blah"
pointLayer = arcpy.env.workspace + os.sep + "Blah" #target point feature class
# Start an edit session. Must provide the worksapce.
edit = arcpy.da.Editor(arcpy.env.workspace)
# Edit session is started without an undo/redo stack for versioned data
# (for second argument, use False for unversioned data)
edit.startEditing(True)
# Start an edit operation
edit.startOperation()
input = arcpy.GetParameterAsText(0)
Range = float(arcpy.GetParameterAsText(1))
# Create empty Point and Array objects
point = arcpy.Point()
array = arcpy.Array()
# A list that will hold each the Polyline object
featureList = []
rows = arcpy.SearchCursor(input)
for row in rows:
geom = row.Shape
point.X = geom.centroid.X
point.Y = geom.centroid.Y
# Add each point to the array
array.add(point)
# Create the polyline
polyline = arcpy.Polyline(array)
# Clear the array for future use
array.removeAll()
featureList.append(polyline)
del row, rows
# Copy the polyline to file geodatabase to create a Shape_Length field
arcpy.CopyFeatures_management(featureList, "line_test")
rows = arcpy.SearchCursor("line_test")
for row in rows:
geom = row.shape
X = geom.lastPoint.X
Y = geom.lastPoint.Y
length = row.Shape_Length / 5.28 + Range
del row, rows
row_value = (length, (X, Y))
cursor = arcpy.da.InsertCursor(fc, ("SiteNum", "SHAPE@XY"))
cursor.insertRow(row_value)
#arcpy.Delete_management("line_test")
# Stop the edit operation.
edit.stopOperation()
# Stop the edit session and save the changes
edit.stopEditing(True)
arcpy.RefreshActiveView()<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>