Select to view content in your preferred language

JavaScript API Connect Directly to SQL Database?

6055
5
08-05-2016 01:39 AM
HenryKo3
Deactivated User

This might sound weird but due to cost and architectural constraints, I need to explore whether it is possible for an ArcGIS API for JavaScript web app to connect directly to a Microsoft SQL database to display (and render) geometries on the web app? In another words, no ArcGIS for Server is involved here - just JavaScript to SQL database. I don't believe this can be achieved.

Tags (2)
0 Kudos
5 Replies
Haider_Ali
Frequent Contributor

JavaScript cannot connect directly to database server you need a middle layer (Web Service) between them

0 Kudos
FC_Basson
MVP Regular Contributor

You will at least need a server-side page (PHP/ASP) to handle the database connect request.  Then you just call the server-side page with an esri.request or AJAX call to retrieve the database query results.

What geometries do you have in the database?  You should be able to construct graphic layer geometries from it in some way.

HenryKo3
Deactivated User

This approach might work for us. We could retrieve the geometries and attributes and construct graphic layers from them. We have points and polygons to display. I think the polygons could be multi-part polygons.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

You will want to fully read and understand if you are compliant with esri Terms of Use:

Terms of Use | ArcGIS for Developers

0 Kudos
JeffJacobson
Frequent Contributor

If your web server is IIS, I would create a REST endpoint using ASP.NET Web API. The SQL query would occur here, on the web server, and return the query result as JSON. Your client-side code (JavaScript) would call this REST endpoint and convert the results into features.

The ArcGIS API for JavaScript is not your only option for creating an interactive map. Leaflet is another alternative you might want to consider. If you go with Leaflet, you'll want your server-side code to return the data from SQL as GeoJSON​.