I have a spatial database in Sql server and I am working in asp.net mvc. My project must show stored shape in web page that uses openlayers js and user must see and edit shapes and send the result to server. I want to know how can I send data to my map and receive new data from it and save data to database.

Is there any library that work for me? Is is not important that it must be open source

thanks a lot

3 Answers 3


You can use Entity Framework or Nhibernate.Spatial to speak to Sql Server. You'll have to solve the OpenLayers vector feature handling yourself in this case.


You can use standard .NET and JS for communication between openlayers and the server.

To get the shape. On the serverside:

[Webmethod, Scriptmethod]
public sting GetShape(string id)
   SqlCommand myCommand = new SqlCommand("SELECT * FROM Shapes WHERE id= '" + id +"'");
   var reader = myCommand.ExecuteReader();
   return reader[geometry].ToString();

You must add a scriptmanager in your aspx code.

On the clientside (JavaScript):

function GetShape(id){
   // PageMethod refers to your C# code and takes three parameter
   // your data, which function to call on suscces, and whic to call on failure
   PageMethod.GetShape(id, GetShapeSucces, GetShapeFailure);

function GetShapeSucces(shape) {
   var wktShape = new OpenLayer.Format.WKT(shape);
   // add the shape to your vector layer

function GetShapeFailure(){

When you have finished editing your shape use the same principles as above to send the geometry and the ID and made and update call to the database. NB! remember to use parameters in your call to the database and not raw input as in the example, because of the risk of SQL-injection


You can use Geoserver to connect to Sql Server, (you would need the SqlServer plugin for this) and then publish the data as WFS-T. On the client side you could use the Openlayers Editor

  • When I use external server software like GeoServer I can not control simple things like permissions and my application business.i want to send and receive data from my .net code and has full control on it.can you suggest me a better way like a good sdk? Feb 21, 2014 at 9:01
  • Have a look at Map Guide then. Never used it but sounds quite powerful and does have .net support. mapguide.osgeo.org/features.html
    – mapoholic
    Feb 21, 2014 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.