Select to view content in your preferred language

Connect and Query Database

4133
4
11-17-2013 04:11 PM
LeAnh1
by
Emerging Contributor
Dear all,
I created some tables in my Arcgis Database. Now, I wanna connect to that DB và query inforamtion. I dont see any example talk about this topic. Anyone can show me smal example. Thanks so much!
P/S: I'm using Esri Runtime QT SDK 10.2, QT 5.1.1, Win 8.1 64bit, Visual Studio 2012.
0 Kudos
4 Replies
JeanneTrieu
Deactivated User
Hi,

Thanks for your feedbacks. Depending on what you would like to achieve, there are a few samples from the ArcGIS Runtime SDK for Qt 10.2 that can help you get started:

http://developers.arcgis.com/en/qt/sample-code/local_geodatabase_editing_sample.htm
http://developers.arcgis.com/en/qt/sample-code/local_query_sample.htm

Regards,
0 Kudos
LeAnh1
by
Emerging Contributor
Hi,

Thanks for your feedbacks. Depending on what you would like to achieve, there are a few samples from the ArcGIS Runtime SDK for Qt 10.2 that can help you get started:

http://developers.arcgis.com/en/qt/sample-code/local_geodatabase_editing_sample.htm
http://developers.arcgis.com/en/qt/sample-code/local_query_sample.htm

Regards,


Thanks for ur answer. But in that examples, just connect to a Arcgis Service with a URL. I wanna connect to a SDEWorkspace, with somes information: DB's server IP, DB's instance, DB's name, usename, password... likely Arcobject .NET or Java. Thanks!
0 Kudos
MikhaelTorstveld
New Contributor
I would be interested in the knowing of this answer as well.  Can runtime make direct connections to existing geodatabases?
0 Kudos
EricBader
Honored Contributor
Hello:

There is a way to do this.

The coding pattern is very similar to what you'll find in the Dynamic Map Layer sample of the ArcGIS Runtime SDK for Qt sample viewer application.

As demonstrated in that example, you'll need to begin by using the LocalMapService along with an "empty" MPK. It's important that you enable dynamic layers on the LocalMapService as well.

QString dataPath = pathSampleData + "mpks" + QDir::separator() + "mpk_blank.mpk";
m_localMapService = EsriRuntimeQt::LocalMapService(dataPath);

m_localMapService.setEnableDynamicLayers(true);


Create a WorkspaceInfo using the static method "CreateSDEConnection", passing in a workspace ID string and the connection string to the SDE instance. Keep in mind, your client machine where this app is running must have the appropriate client libraries installed for the database you are going to connect to, whether it be SQLServer, Oracle, or Postgres, for example. In this case, we are connecting to a SQLServer database:

"INSTANCE=sde:sqlserver:bedrock4;DATABASE=nongdb;USER=map;PASSWORD=map"


// Get the WorkspaceInfoSet from the LocalMapService...
EsriRuntimeQt::WorkspaceInfoSet& workspaceInfoSet = m_localMapService.dynamicWorkspaces();


// create a workspace info via the static method according to data type

m_workspaceId = QString("1");
EsriRuntimeQt::WorkspaceInfo workspaceInfo = 
         EsriRuntimeQt::WorkspaceInfo::CreateSDEConnection(m_workspaceId, QString("INSTANCE=sde:sqlserver:bedrock4;DATABASE=nongdb;USER=map;PASSWORD=map"));


      workspaceInfo.setEditable(true);
      workspaceInfoSet.add(workspaceInfo);
      m_localMapService.setDynamicWorkspaces(workspaceInfoSet);


      // You are ready to start the map service
      m_localMapService.start();


After your LocalMapService has started up successfully, you are ready to add your dynamic layer to the map. It goes something like this:

void Sde_workspace_sample::onLocalServiceCreationSuccess(const QString& url, const QString& name)
{

   // create the ArcGISDynamicMapServiceLayer using the LocalMapService's url
   m_dynamicLocalServiceLayer = EsriRuntimeQt::ArcGISDynamicMapServiceLayer(m_localMapService.urlMapService());
   m_dynamicLocalServiceLayer.setName("MySDELayer");
   m_map.addLayer(m_dynamicLocalServiceLayer);
   m_dynamicLocalServiceLayer.setVisible(true);


   EsriRuntimeQt::DynamicLayerInfoCollection& layerInfos = m_dynamicLocalServiceLayer.dynamicLayerInfos();
   EsriRuntimeQt::DynamicLayerInfo& layerInfo = layerInfos[0];

   // Create some symbology for the added layer
   EsriRuntimeQt::SimpleRenderer simpleRenderer(EsriRuntimeQt::SimpleFillSymbol(QColor("yellow"),EsriRuntimeQt::SimpleFillSymbolStyle::Solid, EsriRuntimeQt::SimpleLineSymbol(QColor("black"), 1, EsriRuntimeQt::SimpleLineSymbolStyle::Solid)));
   EsriRuntimeQt::DrawingInfo countriesDrawingInfo(simpleRenderer, 20);
   layerInfo.setDrawingInfo(countriesDrawingInfo);


   // set dynamic workspaces for our local map service
   EsriRuntimeQt::TableDataSource sdeDataSource;
   sdeDataSource.setWorkspaceId(m_workspaceId);

   // Here is where you identify the feature class you want to add
   sdeDataSource.setDataSourceName(QString("nongdb.map.CALIFORNIA"));

   // Set the layer's datasource
   EsriRuntimeQt::LayerDataSource layerDataSource;
   layerDataSource.setDataSource(sdeDataSource);
   layerInfo.setLayerSource(layerDataSource);


   m_dynamicLocalServiceLayer.refresh();


}


I hope this is helpful! Let us know...
0 Kudos