Use the fdo api to connect to various data sources

Source: Internet
Author: User

Map 3D can connect to various data sources through FDO technology, including SHP files, SDF files, MySQL, SQL Server Spatial, Oracle, and so on. Of course, connecting to different data sources must have different parameters, or be understood as a component of the connection string. What are these parameters? We can use the following code to deeply understand this parameter:

There is not much gossip. You can directly add the code. You can run it in Map 3D to find out its mysteries:

using Autodesk.AutoCAD;using Autodesk.AutoCAD.Runtime;using OSGeo.FDO;using OSGeo.FDO.Commands;using OSGeo.FDO.Commands.Schema;using OSGeo.FDO.Connections;using Autodesk.AutoCAD.EditorInput;using Autodesk.AutoCAD.ApplicationServices;using OSGeo.FDO.Schema;using OSGeo.FDO.Connections.Capabilities;using OSGeo.FDO.ClientServices;using OSGeo.FDO.Commands.DataStore; public class Class1 { IConnection m_pConnection = null; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; FeatureClass m_baseClass; FeatureClass m_riverClass; ProviderCollection m_Providers; string m_sProviderName; [CommandMethod("connect")] public void Connect() { IConnectionManager connMgr; int index; Provider provider; IProviderRegistry registry = FeatureAccessManager.GetProviderRegistry(); m_Providers = registry.GetProviders(); for (int i = 0; i < m_Providers.Count; i++) { provider = m_Providers[i]; ed.WriteMessage(string.Format("FDO support provider {0}, its index is {1} \n", provider.Name, i)); } PromptIntegerResult intRes = ed.GetInteger("please input the provider's index"); if (intRes.Status == PromptStatus.OK) { index = intRes.Value; provider = m_Providers[index]; m_sProviderName = provider.Name; string shortName = provider.Name.Split('.')[1]; try { connMgr = FeatureAccessManager.GetConnectionManager(); m_pConnection = connMgr.CreateConnection(m_sProviderName); IConnectionInfo connInfo = m_pConnection.ConnectionInfo; IConnectionPropertyDictionary properties = connInfo.ConnectionProperties; InputParametersValue(properties); ConnectionState connState = m_pConnection.Open(); ed.WriteMessage("connect status is "+connState.ToString() + "\n"); } catch (OSGeo.FDO.Common.Exception exception) { ed.WriteMessage("There are some exceptions with message : " + exception.Message + "\n"); } } else { ed.WriteMessage("you did not select a correct provider , exit \n"); return; } } [CommandMethod("DisConnect")] public void CloseConnection() { m_pConnection.Close(); } private void InputParametersValue(IConnectionPropertyDictionary properties) { string[] propertiesNames = properties.PropertyNames; foreach (string name in propertiesNames) { PromptStringOptions pso = new PromptStringOptions("Please input the value for \"" + name + "\":"); PromptResult psr = ed.GetString(pso); if (properties.IsPropertyRequired(name)) { while (psr.Status != PromptStatus.OK) { ed.WriteMessage(string.Format("Parameter \"{0}\" is required, please input value again\n", name)); psr = ed.GetString(pso); } properties.SetProperty(name, psr.StringResult); } } } private void ListPropertiesParameters(IDataStorePropertyDictionary properties) { foreach (string name in properties.PropertyNames) { ed.WriteMessage(name + "\n"); } } [CommandMethod("CreateDataStore")] public void CreateDataStore() { ICreateDataStore createDS = m_pConnection.CreateCommand(CommandType.CommandType_CreateDataStore) as ICreateDataStore; IDataStorePropertyDictionary properties = createDS.DataStoreProperties; InputParametersValue(properties); createDS.Execute(); }}

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: 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.