ThinkGeo.com    |     Documentation    |     Premium Support

Looking for SQL 2008 Samples

I’m currently evaluating Map Suite 3.0 for use on a ASP.Net web app and I looking to load all of the objects and layers from a SQL 2008 database. I was looking through the forums for some more in-depth samples since the ones that came with the evaluation don’t seam to connect to my database. I can’t seem to find any so I am hoping you may be able to point me in the right direction. I was also wondering if there may be some more detailed instructions on configuring and pulling a basic shape from as SQL 2008 DB. I found one example ( Post titled : MsSql2008FeatureLayer / using SQL server 2008 to store shape file data). I used the tool to convert the States.shp file into the DB but the evaluation example doesn’t appear to do anything with it.  


here is a snippet of the evaluation code that I tried tweaking.


 


private void LoadAMapFromMsSQL2008()


{


string connectString = "User ID=userid;Password=password;Data Source=MySQL2008DB;";


MsSql2008FeatureLayer sql2008Layer = new MsSql2008FeatureLayer(connectString, "states", "recid");


sql2008Layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;


sql2008Layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;


Map1.StaticOverlay.Layers.Add("Sql2008Layer", sql2008Layer);


}


I have setup the user account etc and it appears to connect with no error but page doesn’t look any different. I even turned off the shape file to see if maybe it was hiding the layer.


The desired shape for my test would be a basic X,Y grid where I could plot specific points within a polygon shape. For instance if I create a shape that looks like a square using an X,Y grid I could dynamically plot points in different areas of the square. Kind of like a splatter point graph. 


Your help is greatly appreciated.


Many Thanks


Sam


 



Sam, 



I think you are asking a Web Edition question in Desktop Edition Forum, Right? :) 



If you just running our sample, please check the aspx page and remove the statement Visible="false" (or change false to true) 



Change 


<cc1:Map ID="Map1" runat="server" Width="100%" Height="100%" Visible="false">

To 

<cc1:Map ID="Map1" runat="server" Width="100%" Height="100%">



We make the Visible to "false" as we cannot provide the database in our sample. When you really want to show it out, please set it to true. 



I had a test just now connecting our Sql Server and spent much time figure out this problem. :) If you still have problem, please let me know more about your code.

Ben



Great this helps alot. I spent 2 days off and on trying to figure out why nothing was happening and I didn’t think to look in the ASPX page. I was only looking at the code behind.


I set it to true but now I get an Object reference not set error. 
 
Yes this was for the Web Support I guess I posted it in the wrong forum. If you want to move this post to the Web Support forum that would be ok with me. I will poke around there and see if I can find some additional examples too.
 
Thanks 
Sam
 

 



Sam, 
  
 It’s our fault that we should make a note or something in the sample to remind people. We will do it in the coming release. 
  
 About your “Object reference not set error”, can you create a simple demo and send to us to recreate, we tested with our SQL2008 sample and that works fine, just wonder if some other places going wrong.  
  
 Ben. 


Well I was thinking it may have been a result of the changes I was making to try and get it to work so I decided to uninstall the eval software and reinstall it so the Samples would restore to thier original state. I think there is an issue with unistalling since when I went to reinstall the installer threw a 2908 error. Then all of my MS Office apps stopped working. I couldnt repair or use a System restore to roll back so Im stuck reinstalling my os.


Basicly what I had done was use the following tool to convert the States.shp file from the samples into a table on my 2008 SQL instance. Then I just pointed to that table.


Here was the code I used.


private void LoadAMapFromMsSQL2008()


{


string connectString = "User ID=userid;Password=password;Data Source=MySQL2008DB;";


MsSql2008FeatureLayer sql2008Layer = new MsSql2008FeatureLayer(connectString, "states", "recid");


sql2008Layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;


sql2008Layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;


Map1.StaticOverlay.Layers.Add("Sql2008Layer", sql2008Layer);


}


Im thinking maybe the table was setup wrong or that the column I need to refference was incorrect.


Here is the link to the post that showed the tool that converts the shapefile to a SQL 2008 table.


gis.thinkgeo.com/Support/Dis...fault.aspx


Once Im back up and running I will try to recreate this again.


Also are there any special setup instructions for the SQL connection? Do I need to setup an ODBC DSN or anything? It didnt appear to need them but I figure I would ask. This area seams a bit vague or maybe I overlooked something. Also are there requirments for the table that this needs to connect to?


Many Thanks


Sam



Sam, 
 I’m sorry you reinstall the system because of the issues with uninstalling the eval edition. I have no idea about that problem and we will have a test. 
 We didn’t do anything special during the data conversion, it’s strange you cannot use it.  Here is some simple code please try if it works on your machine? If it passed, we can say the database is successfully set up. 
  
 
String connectionString = “Data Source=192.168.0.100,1041;Initial Catalog=InternalDB;Persist Security Info=True;User ID=sa;Password=password”;

SqlConnection sqlConnection = new SqlConnection(connectString);
            try
            {
                sqlConnection.Open();
                SqlCommand sqlCommand = new SqlCommand(“Select Count(*) from STATES”,sqlConnection);
                //count should be 51.
                int count = (int)sqlCommand.ExecuteScalar();
           }

            finally
            {
                sqlConnection.Close();
            }
 
  
 If the codes work fine, I think you can get all records and see if anything is wrong there.  Let us know what you find. 
  
 Ben.

Ok I reinstalled everything and reloaded the table etc and I am able to load the States etc, and the sample is working. Maybe I just had a bad install or something.


In any case, thank you very much.


Sam


 



That’s great! Let us know for more queries.  
  
 Ben