About exceptions from hresult:0x80040351

Source: Internet
Author: User
Tags polyline

The error "Exception from hresult:0x80040351" occurred today when opening a workspace operation.

After analysis, it is found that the corresponding relationship between the Iworkspacefactory implementation classes is incorrect. Originally wanted to manipulate the. gdb file in the database, but the declaration was written as iworkspacefactory workspacefactory = new Shapefileworkspacefactory (); Later changed to iworkspacefactory workspacefactory = new Filegdbworkspacefactoryclass (); The problem is solved. Ashamed...

Go to "open a connection to various data sources (WorkSpace) in Arcengine", data source types include SDE, Personal/file, shapefiles, CAD data, imagery, and image datasets.

1. The Enterprise Database (SDE) enterprise database needs to be managed using SDE, so you need to use SDE's workspace to represent the connection. In the AE interface, the workspace is opened by factory. The code is as follows:

Prepare the connection Parameters ESRI.ArcGIS.esriSystem.IPropertySet ppropset=new propertysetclass ();pP ropset.setproperty ("Server", " Server machine name ");pP Ropset.setproperty (" instance "," Sde Run port number ");pP ropset.setproperty (" User "," username ");pP ropset.setproperty ( "Password", "password");pP ropset.setproperty ("Version", "edition"); Sdeworkspacefactory sdewkspfact=new Sdeworkspacefactoryclass (); Ifeatureworkspace pFeaWksp= (IFeatureWorkspace) Sdewkspfact.open (ppropset,0); the only thing that needs to be explained is version. For no use of the version or for the first connection (no spatial database is established, of course there is no version). The service uses SDE. The default version. This is the default version. Ipropertyset:: Setpropertypublic void SetProperty (string name,object value)
2. Personal database (Personalgeodatabase, filegeodatabase) arcengine in personal database is access. String filepath= "E:\\tt.mdb"; Accessworkspacefactory fac=new Accessworkspacefactoryclass (); Ifeatureworkspace space= (IFeatureWorkspace) FAC. Openfromfile (filepath,0); This is one of the most used ways. If it is Filegeodatabasse, it will filegdbworkspacefactory pwsf = New filegdbworkspacefactory;ifeatureworkspace pWS1 = Pwsf.openfromfile (spath, 0); If you use Ipropertyset. As follows://personal geodatabase e.g., database = "C:\\mydata\\mypgdb.mdb" Public iworkspace open_pgdb_workspace (string Database) {Ipropertyset PropertySet = new Propertysetclass ();p ropertyset.setproperty ("database", database); Workspacefactory workspacefactory = new Accessworkspacefactoryclass (); return Workspacefactory.open (PropertySet, 0);}
3.Shapefile files Shapefiles and access are opened in a bit the same way. There are also differences. This is the directory where shape is located (note: is the directory) string spacepath= "E:\\shapefile"; Ishapefileworkspacefactory fac=new Shapefileworkspacefactoryclass (); Ifeatureworkspace space= (ifeatureworkspace) FAC. Openfromfile (spacepath,0); Ifeatureclass fc=space.openfeatureclass ("China");
4.AutoCAD dwg files AutoCAD files are different from the general ESRI format. So the code will be a little bit strange. Suppose there is a DWG file for E:\\CAD\\107.DWG below is the Open code: Cadworkspacefactoryclass fac=new cadworkspacefactoryclass (); String filepath= "E:\\cad"; Ifeatureworkspace Space=fac. Openfromfile (filepath,0) as Ifeatureworkspace; The following is the code to open Featureclass://Line Ifeatureclass polyline =space. Openfeatureclass ("107.dwg:polyline"); Ifeaturelayer layer=new cadfeaturelayerclass (); layer. Featureclass =polyline;//Point Ifeatureclass point=space. Openfeatureclass ("107.dwg:point"); layer=new cadfeaturelayerclass (); layer. Featureclass =point;//noodles Ifeatureclass polygon=space. Openfeatureclass ("107.dwg:polygon"); layer=new cadfeaturelayerclass (); layer. Featureclass =polygon;//Note Ifeatureclass anno=space. Openfeatureclass ("107.dwg:annotation"); Layer=new cadannotationlayerclass (); layer. Featureclass =anno;
5. image File//file path string filepath= "E:\\image\\117.tif"; Irasterlayer rasterlayer=new Rasterlayerclass (); Rasterlayer.createfromfilepath (FilePath);
6. The image dataset in the database. Database connection Iworkspace space=openspace ();//How to open the database Irasterworkspaceex rasterspace= (Irasterworkspaceex) space;i Rasterdataset Rasterdataset=rasterspace.openrasterdataset (setname.name); Irasterlayer rasLayer=new Rasterlayerclass (); Raslayer.createfromdataset (Rasterdataset); Irasterworkspaceex: Provides a way to create and open a raster catalog or raster dataset. But Irasterworkspaceex,irasterworkspace, IRasterWorkspace2 all have openrasterdataset. Irasterworkspace can often also be used to open raster data, such as:
Pworkspacefactory = new Rasterworkspacefactoryclass ();p rasterworkspace = (irasterworkspace) Pworkspacefactory.openfromfile (FilePath, 0); Irasterdataset prasterdataset = (irasterdataset) Prasterworkspace.openrasterdataset (fileName); Irasterlayer prasterlayer = new Rasterlayerclass (); Prasterlayer.createfromdataset (Prasterdataset);

  

About exceptions from hresult:0x80040351

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.