Timeout occuring using MsSqlSpatial with SharpMap

Topics: User Forum
Jan 24, 2007 at 1:56 PM
Hi folks,

I posted the message below in the SharpMap forums earlier today:

--- start ---
I'm trying to do something very similar to the OP - ie. trying to filter the data returned by MsSqlSpatial. I found that if I use, for example:

map.ZoomToBox(new SharpMap.Geometries.BoundingBox(311667.753574452, 168321.2111899, 312732.700916047, 168900.648377004));

Even though the image is actually produced and saved by my Web application, and it shows the correct area (in beautiful quality, I might add!), I get a timeout error from the actual webpage. Ie.

"Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding."

The stacktrace shows:

"SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +857242
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +734854
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1838
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +31
System.Data.SqlClient.SqlDataReader.get_MetaData() +62
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +886
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
System.Data.SqlClient.SqlCommand.ExecuteScalar() +137
SharpMap.Data.Providers.MsSqlSpatial.GetExtents() +220
SharpMap.Layers.VectorLayer.get_Envelope() +43
SharpMap.Map.GetExtents() +76
SharpMapTest.Test.Page_Load(Object sender, EventArgs e) +1242
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061"

Now this is weird as the image is produced and saved to the temporary directory in around a second or so, yet the application appears to be still working and times out.

If I remove the MsSqlSpatial layer from the application, ie. leaving just layers from SHP files, there is no problem and it doesn't timeout.

Any ideas as to what's going on here?
--- end ---

If anyone is able to help, I'm very grateful! The original thread can be found here http://www.codeplex.com/SharpMap/Project/DisplayThread.aspx?ForumId=396&ThreadId=3847 but answers in this forum would be fine too :)

Cheers,

Dylan
Coordinator
Jan 25, 2007 at 2:15 AM
Help me so I can help you. Please, send me working sample code and, if possible, the data you're trying to load.

Best regards,
Ricardo Stuven.
Jan 25, 2007 at 9:19 AM
Here's an example of the code I am using. It's really down to the bare bones of the code, with a simple output of how long the image took to produce. It times out though, so this is never displayed, even though the image (example.png) is actually saved to the specified location.

--- start ---
using System;
using System.Drawing;
using SharpMap;

namespace SharpMapTest {
public class Test : System.Web.UI.Page {
public void Page_Load(object sender, EventArgs e) {
DateTime start = DateTime.Now;

// Create new map
SharpMap.Map map = new Map();
map.Size = new System.Drawing.Size(800, 600);
map.BackColor = Color.White;

// Add a layer
SharpMap.Layers.VectorLayer layer = new SharpMap.Layers.VectorLayer("Test");
SharpMap.Data.Providers.MsSqlSpatial myData = new SharpMap.Data.Providers.MsSqlSpatial("Server=localhost;Database=opus2;Uid=**;Pwd=**", "data", "the_geom", "oid");
layer.DataSource = myData;
layer.Style.Line.Color = Color.Gray;
map.Layers.Add(layer);

map.ZoomToBox(new SharpMap.Geometries.BoundingBox(311667.753574452, 168321.2111899, 312732.700916047, 168900.648377004));

System.Drawing.Image image = map.GetMap();
image.Save(System.Web.HttpContext.Current.Server.MapPath("/SharpMap/example.png"), System.Drawing.Imaging.ImageFormat.Png);

DateTime end = DateTime.Now;
TimeSpan time = end - start;

Response.Write("The file was created in " + time.TotalMilliseconds + "ms");
}
}
}
--- end ---

Unfortunately I can't send you the data as it's 176MB in size (as a shape file) and supplied under license anyway :(
Jan 25, 2007 at 9:28 AM
Heh, looks like you helped me to help myself! After stripping down the code to the bare bones so I could post you an example, I discovered that it suddenly worked. I had removed a line in the code "map.GetExtents()" that I didn't need any more as it didn't really serve any useful purpose, and it then ran fine both creating the image and outputting the "time to complete" message in just over a second :)

Cheers for encouraging me to "fend for myself" <g>
Coordinator
Jan 25, 2007 at 7:13 PM
This discussion has been copied to Work Item 7645. You may wish to continue further discussion there.
Jan 26, 2007 at 9:06 AM
Resolved already? Wow, that was quick! I suppose the next question I should ask, is what steps do I need to take to download, compile and upgrade the new code?

Cheers,
Coordinator
Jan 26, 2007 at 12:37 PM
This need a change in SharpMap's MsSqlSpatial provider also. I will commit it when the next version of MsSqlSpatial be released. That will happen when I resolve an issue first. Please be patient

Best regards,
Ricardo Stuven.
Jan 26, 2007 at 12:42 PM
That's great, thanks.