This project has moved. For the latest updates, please go here.

Cannot call methods on image.

Topics: Data Access
Jan 8, 2011 at 12:34 PM

Hi everybody, I am a sharpmap newbie. I  have a problem with sql server 2008.

When l load layer data from Sql Server 2008 (express). It displays error 'Cannot call methods on image'.

This is my code from MapHelper.

        layer.DataSource = new    SharpMap.Data.Providers.SqlServer2008(connectionString, "myTable", "WKB_Geometry", "oid"); 

        layer.Style.Fill = new SolidBrush(Color.Red);
        layer.Style.Outline = System.Drawing.Pens.Blue;
        layer.Style.EnableOutline = true;


And the error appears in method GetGeometriesInView class SqlServer2008.cs  of Sharpmap.Data.Provider

       public Collection GetGeometriesInView(SharpMap.Geometries.BoundingBox bbox)   
           Collection features = new Collection();   
           using (SqlConnection conn = new SqlConnection(_ConnectionString))   
               //Get bounding box string   
               string strBbox = GetBoxFilterStr(bbox);   
               string strSQL = "SELECT g." + this.GeometryColumn +".STAsBinary() ";   
               strSQL += " FROM " + this.Table + " g WHERE ";   
               if (!String.IsNullOrEmpty(_defintionQuery))   
                   strSQL += this.DefinitionQuery + " AND ";   
               strSQL += "g." + strBbox;   //I added "g."
               using (SqlCommand command = new SqlCommand(strSQL, conn))   
                   using (SqlDataReader dr = command.ExecuteReader())  //error appears here 
                       while (dr.Read())   
                           if (dr[0] != DBNull.Value)   
                               SharpMap.Geometries.Geometry geom = SharpMap.Converters.WellKnownBinary.GeometryFromWKB.Parse((byte[])dr[0]);   
           return features;   

I am a newbie, please help me.

Jan 10, 2011 at 7:41 AM

Hello namserious,

why did you add

strSQL += "g." + strBbox;

? GetBoxFilterStr(bbox) should provide the necessary clause for the spatial query. If it does not work without the clause, could you post the Schema of your SqlServer2008 database table.

Hth FObermaier

Jan 10, 2011 at 3:27 PM

Hey, thank you for replying.

If I don't use "g." here it will display error that means 'ambiguous'

Here is my database constructor

Jan 11, 2011 at 7:25 AM

cities and countries, are those imported shapefiles from the sample data folder or something different?

If they are different, could you post the CREATE statement or column definition?

cheers FObermaier

Jan 11, 2011 at 9:16 AM
Edited Jan 11, 2011 at 9:19 AM

Oh, my leader very smart, he found a tool that allows inserting file. shp into database directly. We only insert path of file .shp into a textbox and press button :D.

I have repaired it when I used "SharpMap.Data.Providers.MsSql(..........)"

You are so enthusiastic. Good luck to you.