Select to view content in your preferred language

How to query a non-ArcGIS database from WAB?

5911
41
Jump to solution
01-12-2017 02:35 PM
WilliamMiller4
Occasional Contributor II

Hi,

I need to send information from my WAB app to a non-ArcGIS database, run a query and return the results back to my app. From what I see online, using only JavaScript is not a secure idea. It looks like I need an intermediary, which my employer would like to be Visual Basic. If someone has successfully done this, please let me know how I might go about it. Any help is appreciated. Thank you for your time.

William

0 Kudos
41 Replies
Drew
by
Regular Contributor

You would have to know the database, table name and the credentials to connect to the database.

• Assuming it’s a SQL Server database, its just like connecting to SDE and adding data the same way.
• Add a database connection in ArcCatalog
• In ArcMap just use the add data button and browse to your table.
• Once added got to the table of contents and select the ‘List by Source’ icon to see the able listed.
• Publish to ArcGIS Server
o You might have to register the database with ArcGIS Server
• Navigate to the map services REST endpoint and look for your table.
• You now have a layer you can query using the JSAPI

Drew

WilliamMiller4
Occasional Contributor II

Hi Drew,

The database has been added to the ArcGIS Rest Services Directory. Do I use esri/Request to query it?

William

0 Kudos
Drew
by
Regular Contributor

So you published a map service with the table in it?
You can test your data by clicking on the table in the REST endpoint and selecting the 'Query' operation link at the bottom of the page.
Just query where 1=1 and you should see some results.


In JavaScript you can just use the QueryTask to query the data.

QueryTask | API Reference | ArcGIS API for JavaScript 3.19 

Drew

WilliamMiller4
Occasional Contributor II

Hi Drew,

Below is my code for the QueryTask. 

var queryString = this._buildQueryString();
var query = new Query();
var queryTask = new QueryTask("URL_OF_ARCGIS_REST_SERVICE");
query.where = queryString;
query.outFields = ["ACCOUNT_NBR", "ADDRESS_LINE_1", "PROP_ZIP", "TOT_VAL", "LAND_VALUE", "BUILDING_VALUE", "SDWLL_NBR", "ROUTING_NBR", "LIVING_SPACE", "Sch_Dst_Dsc"];
queryTask.execute(query, lang.hitch(this, this._onSuccessfulQueryCompletion), lang.hitch(this, this._onFailedQueryCompletion));

When I run this code, the _onSuccessfulQueryCompletion executes.

_onSuccessfulQueryCompletion: function(results) {
      console.log('RatioQuery::_onSuccessfulQueryCompletion');
      
      new Message({
        titleLabel: "Ratio Query",
        message: "SUCCESS"
      });
      
      console.info(results);
    },

However, when I look at the data in the console, I don't see where any results are. Below is what displays in Chrome.

console.info(results); screenshotWhat am I doing wrong?

Thank you for all your help.

William

0 Kudos
Drew
by
Regular Contributor

Your Close..

Point your "URL_OF_ARCGIS_REST_SERVICE" to the 'layer'

Sample

http://<MYDOMAIN>arcgis/rest/services/MyTableService/MapServer/1



WilliamMiller4
Occasional Contributor II

Hi Drew,

If you have a chance, I have a related question that I just posted as a separate thread.

https://community.esri.com/message/665313-how-to-connect-data-to-a-map 

Thanks for all your help!

William

0 Kudos
Drew
by
Regular Contributor

William,
I would look into the WebAPI by Microsoft to create your Web Service. It's RESTful and easy. Check out YouTube for some tutorials.

WebAPI
ASP.NET Web API | The ASP.NET Site 

Another idea is to just add your standalone table into a map service. Not all data in an MXD has to be Spatial. You can query tables too.

Drew

WilliamMiller4
Occasional Contributor II

Hi Robert,

Did you use WCF, MVC or something else to create your web services?

Thank you.

William

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Nope just a simple VB.net RESTful web service.

0 Kudos
WilliamMiller4
Occasional Contributor II

But you did use the .Net Web API, right?

0 Kudos