.net开发Arcengine访问access数据库时,如果同时使用engine和ado访问数据库,结果arcMap直接崩溃

.net开发Arcengine访问access数据库时,如果同时使用engine和ado访问数据库,结果arcMap直接崩溃,第1张

空间数据库用ArcEngine *** 作,没问题;

关系数据库用ADO.net *** 作,没问题;

问题是 使用AE接口将其当做空间库 *** 作后又将其当做关系库然后使用ado *** 作!混搭是会出问题的!

实际上,AE自己有执行sql语句的功能,不要再用自己的ado访问,统一用ae接口。

如果执行 查询 *** 作,使用IQuerydef接口;

如果执行 删除,修改,插入等无返回值的sql语句,直接ExcuteSQL接口即可。

具体用法再查询。当前你应该做的是用这两个接口,改写你所有的ado处理方法,程序中将移除所有的ado,再看结果如何。

原因:打开空间数据库的工作空间,实际上也打开了数据库连接。混搭 *** 作,可能由于你不了解资源的释放等,产生不可预知的错误,也许逻辑是对的,得不到你想要的结果。。。

http://www.pudn.com/downloads295/sourcecode/graph/detail1322386.html

资源站上给你找了一段代码,这个肯定够你用的。

private void button1_Click(object sender, EventArgs e)

{

//dem数据一般读的是包含所有adf文件的文件夹的名称

OpenFileDialog openFile = new OpenFileDialog()

openFile.ShowDialog()

string path = openFile.FileName

//判断后缀是否为adf,如果是则读取它路径的上一级作为文件名

string lastname = path.Substring(path.Length - 3, 3)

string frontname = null//该字符串记录的事排除后缀为adf文件名的路径

if (lastname == "adf")

{

char[] split = new char[] { '\\' }

string[] array = path.Split(split)

string last = array[array.Length - 1]//XXX.adf

int n = last.Length + 1

frontname = path.Substring(0, path.Length - n)

}

if (frontname != null)

{

ILayer pLayer = openDEMLayer(frontname)

this.axSceneControl1.Scene.AddLayer(pLayer, true)

}

}

public static ILayer openDEMLayer(string fullPath)

{

string pathToWorkspace = System.IO.Path.GetDirectoryName(fullPath)

string demName = System.IO.Path.GetFileName(fullPath)

IWorkspaceFactory pWSFact = new RasterWorkspaceFactoryClass()

IWorkspace pWS = pWSFact.OpenFromFile(pathToWorkspace, 0)

IRasterWorkspace pRasterWorkspace = pWS as IRasterWorkspace

IRasterLayer pRasterLayer= new RasterLayerClass()

try

{

IRasterDataset pRasterDataset = (IRasterDataset)pRasterWorkspace.OpenRasterDataset(demName)

pRasterLayer.CreateFromDataset(pRasterDataset)

}

catch (Exception err)

{

MessageBox.Show(err.Message)

}

return pRasterLayer

}

private void button2_Click(object sender, EventArgs e)

{

IRasterLayer pRasterLayer = new RasterLayerClass()

pRasterLayer = (IRasterLayer)axSceneControl1.Scene.get_Layer(1)//Raster图层

IRaster pRaster = pRasterLayer.Raster

ISurfaceOp pSurfaceOp = new RasterSurfaceOpClass()

ILayer pLayer = axSceneControl1.Scene.get_Layer(0)//点图层

IFeatureLayer pFeatureLayer = (IFeatureLayer)pLayer

IGeoDataset pObservers = (IGeoDataset)pFeatureLayer.FeatureClass

IGeoDataset pGeoDataset = pSurfaceOp.Visibility((IGeoDataset)pRaster, pObservers, esriGeoAnalysisVisibilityEnum.esriGeoAnalysisVisibilityFrequency)

IRasterLayer pNewRasterLayer = new RasterLayerClass()

IRaster pNewRaster = new ESRI.ArcGIS.DataSourcesRaster.Raster()

pNewRaster = (IRaster)pGeoDataset

pNewRasterLayer.CreateFromRaster(pNewRaster)

pNewRasterLayer.Name = "透视图"

axSceneControl1.Scene.AddLayer(pNewRasterLayer, false)

}

private void button3_Click(object sender, EventArgs e)

{

OpenFileDialog openFileDialog1 = new OpenFileDialog()

openFileDialog1.Filter = "shapefile文件(*.shp)|*.shp"

//获取或设置文件对话框显示的初始目录

//openFileDialog1.InitialDirectory = @"D:\Program Files\ArcGIS\Metadata\Data"

//获取或设置一个值,该值指示对话框是否允许选择多个文件

openFileDialog1.Multiselect = false

// 运行具有指定所有者的通用对话框

DialogResult pDialogResult = openFileDialog1.ShowDialog()

//指定标识符以指示对话框的返回值

if (pDialogResult != DialogResult.OK)

return

//获取或设置一个包含在文件对话框中选定的文件名的字符串

string pPath = openFileDialog1.FileName

//返回指定路径字符串的目录信息

string pFolder = System.IO.Path.GetDirectoryName(pPath)

//返回指定路径字符串的文件名和扩展名

string pFileName = System.IO.Path.GetFileName(pPath)

IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory()

IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(pFolder, 0)

IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace

IFeatureClass pFC = pFeatureWorkspace.OpenFeatureClass(pFileName)

IFeatureLayer pFLayer = new FeatureLayerClass()

pFLayer.FeatureClass = pFC

pFLayer.Name = pFC.AliasName

ILayer pLayer = pFLayer as ILayer

axSceneControl1.Scene.AddLayer(pLayer, true)

}

在工具箱中,就你选择的指针上面那个ArcGIS Windows Forms,右击它,在右键菜单中选择“选择项”;

等待片刻后,因为dll很多,要花点时间加载,出来对话框后,显示一堆dll,你往下翻,找到mapcontrol,勾选,加载进来


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/10871194.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-11
下一篇 2023-05-11

发表评论

登录后才能评论

评论列表(0条)

保存