Tonyalmeida

data source SQL Server Express databases

Discussion created by Tonyalmeida on Jan 30, 2014
Latest reply on Jan 30, 2014 by Tonyalmeida
I need to update about 25 mxd's layers data source. The layers old data source is an SDE workspace, but now have moved to a SQL Server Express databases. In the help They indicate that i have to a create a spatial database connection to the SQL Server Express database. I am not sure how to create a spatial database connection and update the mxd's layers in python.
I would appreciate any help.

Here are some of the MXD's layers that i need the data source updated on.

Layer IMPACT AREA old location (C:\Users\t**a\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\DBO.DSD.VECTOR.sde\dsd."CC\TALMEIDA".DEVELOPEMENT\dsd."CC\TALMEIDA".CURRENT_IMPACT_AREA)

New IMPACT AREA location(C:\Users\t**a\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\DSD15_SQLEXPRESS.gds\DSD\DSD.DBO.DEVELOPEMENT\DSD.DBO.CURRENT_IMPACT_AREA

Layer FLOODWAY old location (C:\Users\t**a\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\DBO.DSD.VECTOR.sde\dsd."CC\TALMEIDA".FEMA09\dsd."CC\TALMEIDA".FEMA09_FLOODWAY)

New FLOODWAY location (C:\Users\t**a\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\DSD15_SQLEXPRESS.gds\DSD\DSD.DBO.FEMA09\DSD.DBO.FEMA09_FLOODWAY)

Layer Zoning old location (C:\Users\t**a\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\DBO.DSD.VECTOR.sde\dsd."CC\TALMEIDA".MUNICIPALITY\dsd."CC\TALMEIDA".CURRENT_ZONING)

New Zoning location (C:\Users\t**a\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\DSD15_SQLEXPRESS.gds\DSD\DSD.DBO.MUNICIPALITY\DSD.DBO.CURRENT_ZONING)

This is my current code.

import arcpy, os
from arcpy import env
from arcpy import mapping


arcpy.env.overwriteOutput = True

path = r'C:\GIS\MAPBOOK\Proposed Zoning Book\test'
for fileName in os.listdir(path):
   fullPath = os.path.join(path, fileName)
   if os.path.isfile(fullPath):
      basename, extension = os.path.splitext(fullPath)
      if extension == ".mxd":
         mxd = arcpy.mapping.MapDocument(fullPath)
         print fullPath
         print mxd
         for lyr in arcpy.mapping.ListLayers(mxd):
            if lyr.name == "PROPOSED ZONING":
                lyr.replaceDataSource(r"C:\Users\t**a\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\DSD15_SQLEXPRESS.gds\DSD\DSD.DBO.MUNICIPALITY", "SDE_WORKSPACE", "DSD.DBO.FUTURE_LAND_USE_ZONING")
            elif lyr.name == "CITY LIMITS":
                lyr.replaceDataSource(r"C:\Users\t**a\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\DSD15_SQLEXPRESS.gds\TonyOneWay\TonyOneWay.DBO.Canyon_Features", "SDE_WORKSPACE", "TonyOneWay.DBO.City_Limits")            
         print "Successfully updated data sources"
         mxd.save


It gets stuck on line 21 with this error
C:\GIS\MAPBOOK\Proposed Zoning Book\test\Proposed_ZoningMapBook_Page_10.mxd
<geoprocessing Map object object at 0x02C0F740>

Traceback (most recent call last):
  File "C:\GIS\Python Scripts\Change Data Source MXD 2.py", line 21, in <module>
    lyr.replaceDataSource(r"C:\Users\talmeida\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\DSD15_SQLEXPRESS.gds\TonyOneWay\TonyOneWay.DBO.Canyon_Features", "SDE_WORKSPACE", "TonyOneWay.DBO.City_Limits")
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_
    return fn(*args, **kw)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\_mapping.py", line 680, in replaceDataSource
    return convertArcObjectToPythonObject(self._arc_object.replaceDataSource(*gp_fixargs((workspace_path, workspace_type, dataset_name, validate), True)))
ValueError: Layer: Unexpected error

Outcomes