替换mxd的shp图层的数据源后保存时,报错{System.Runtime.InteropServices.COMException (0x80030021): 未找到数据库,请问这是什么原因?

arcengine10.2进行add-in开发,错误信息:{System.Runtime.InteropServices.COMException (0x80030021): 未找到数据库。
在 ESRI.ArcGIS.Carto.MapDocumentClass.Save(Boolean bUseRelativePaths, Boolean bCreateThumnbail)
代码:
IMapDocument mapDoc = new MapDocumentClass();
mapDoc.Open(mxdPath);
IDataSourceHelperMapDocument repairment = new DataSourceHelperClass();
IWorkspaceName oldWorkspaceName = new WorkspaceNameClass();
oldWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory";
oldWorkspaceName.PathName = oldPath;
IWorkspaceName newWorkspaceName = new WorkspaceNameClass();
newWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory";
newWorkspaceName.PathName = System.IO.Path.Combine(newPath, fileName);
repairment.ReplaceWorkspaceName(mapDoc, oldWorkspaceName, newWorkspaceName, true);

mapDoc.Save(true, true);
 
第二种方法:
IMapDocument mapDoc = new MapDocumentClass();
mapDoc.Open(mxdPath);
IMap pMap = mapDoc.get_Map(0);
ILayer pLayer = GetLayerByName(layerName, pMap);
IDataLayer dataLayer = (IDataLayer)pLayer;
                            IDatasetName pDsName = (IDatasetName)(dataLayer.DataSourceName);
                            IWorkspaceName ws = pDsName.WorkspaceName;
                            string path = "test2"; 
                            string newPath = System.IO.Path.Combine(folderPath, path);
                            ws.PathName = newPath;
                            bool ss = mapDoc.get_IsReadOnly(mapDoc.DocumentFilename);
                            mapDoc.Save();
报相同的错误database not found
已邀请:

yiliyanyu

赞同来自:

其中mapDoc的isread_only为false,shp图层的数据源缺失(显示小红点),用代码进行替换修复

xiaosi9524 - GISER

赞同来自:

调试看下路径对不对

朱新颖

赞同来自:

看下ArcMap有没有打开该mxd,打开的话保存会报错。

要回复问题请先登录注册