spacer1
spacer2 1_1 1_2
2_1
 Subscribe
 The MP2K Update!
 
 
 
 Magazine
Front Cover
What's New
Articles
News
Sample Data
Gallery
Advertise
About
 Features
MapPoint 2009
Press Releases
MapPoint Forums
Companies
Link to MP2Kmag
Wish List
MapPoint Trial
Authors
 Earlier Content
Past News Items
Past What's New Announcements
 Sponsors
 Order

MapPoint 2009

Programming MapPoint in .NET

MapPoint Book

  Spatial Community
SVG Tutorials
MapPoint

Map Visitors

 Direct Media

Travel Insurance Compare over 450 travel insurance policies (inc. annual multi-trip, single trip & winter sports)

  ARTICLES  


Using a DSN-less Connection to a SQL Server Database to Get Data for Maps

Whether you are building a COM add-in or using the MapPoint ActiveX Control, you may need to access SQL Server data. Here are some ideas on doing it efficiently and flexibly.

Article assumptions:

  • You have a basic understanding of data access.
  • You need to get at SQL Server data to do something with MapPoint.

(Let me apologize in advance about how I have mixed VB code with SQL Server table, view and stored procedure definitions in this article. My goal is to give you all of the elements you need to dynamically grab SQL data and make it available in MapPoint. I hope I have succeeded.)

MapPoint provides import and linking support for SQL Server data, but that is limited by the need for using Universal Data Link as the mechanism to get at SQL Server data. You can't execute dynamically created SQL or SQL Server stored procedures. Therefore, we need a way to get data onto maps in a more flexible way. We can use a DSN-less connection in our code to get at SQL Server data and create points from that data.

Why go DSN-less?

In an MSDN article called Improving ASP Application Performance, there are several interesting data access performance tips that are not specific to ASP.

  • In general, DSN-less connections are faster than System DSNs (data source names), which are faster than File DSNs.
  • Microsoft Access is a file-based database, so don't expect it to perform well with concurrent users under IIS [or otherwise].
  • For SQL Server, SQLOLEDB, the SQL provider, is recommended over MSDASQL, the OLEDB provider for ODBC for performance and reliability.
  • It is always good practice to explicitly close your object variables.

The code below shows a number of ways to make connections and create recordsets:

The table I use in SQL Server 2000 for holding locations looks like this:

Once you have a recordset, you can start creating MapPoint objects.

A more advanced way to make use of SQL Server would be to use stored procedures. See the following examples for ideas. This works best in an environment that uses integrated SQL security. Instead of providing the User ID and password in the connection string, it looks like this: "Provider=SQLOLEDB;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Northwind;Data Source=MyServer". This passes the NT/2000 Domain login information already available from the person logged in on the workstation, and provides it to SQL Server as the login information for the database.

If you use integrated security, then you can use the SQL Server function "suser_sname()" to get the DOMAIN\UserID of the person running the application that is accessing SQL Server.

Now create a view to allow each user to get the data tahe he or she added [call it "vwMapDisplay"]:

This view can now be used to import selected data into MapPoint using:

What is the use of all of this... Addins and VB programs using the MapPoint ActiveX Control can be configured to apply very sophisticated logic to the display of map data drawn from the underlying SQL Server database. How far you want to take this becomes completely up to you.

Clearly the one enhancement to MapPoint that would simplify this whole thing would be the ability to import an ADO recordset directly into a MapPoint Dataset. I am looking forward to seeing the object model for the next version of MapPoint to see what data handling improvements are added.

Discuss this story in the forum.

Author: Walt Cygan
Email: wcygan(AT)macrogroup.net
URL: http://www.macrogroup.net
Walt is a consultant for The MACRO GROUP, Inc. in Minneapolis, Minnesota. The MACRO GROUP, Inc. is an information systems consulting firm whose customers include public, private and non-profit organizations of all sizes.



Google
 
MP2Kmag Internet


 Recent Discussion
-bingmaps: @redwanhuq I mean, what exactly is inaccurate? Can you provide the info you're searching for? Slowness could be connectivity.
-BingMapsDev: Reading @Chrispendleton article 'The world according to Bing' http://bit.ly/9mmoWy
-Easy game maker to make games like day of the tentacle or platform games?
-bingmaps: "The Thing About Bing" CP interview published in @gim_intl mag: http://bit.ly/b4l6eJ. Avail free online. ^CP
-bingmaps: Add Bing (Maps) to Your Safari Browser Extensions: http://bit.ly/aFeDsd. ^CP
-bingmaps: Here's a fun video: 10 Places not on Google Earth: http://bit.ly/bTcx1Y. ^CP
-MapPoint or alternative for Haiti?
-bingmaps: RT @gim_intl: ^JB We have published an interview with #Microsoft #Bing #Maps's @chrispendleton - now available online! http://ht.ly/2ik9f
-Problem with FindAddressResults
-Map multiple layers on one map
-bingmaps: Nice to see @MSFTResearch project Street Slide outside the firewall: http://j.mp/bUUYTu. ^CP
-SpatialImportDll_Feature colour Display
-bingmaps: See the updated Bing Twitter Map App? Photo pins, sharing, tabbed searches walk thru embedded maps: http://bit.ly/9rnCaL ^CP
-bingmaps: @redwanhuq Whatchu talkin' bout Willis? Details of your setup please...
-bingmaps: @zafeuer Pretty sure that's comScore rankings. ^CP
-Copying thematic maps from MapPoint 2010 to Excel/Word 2007
-Export territory data
-bingmaps: @mackenziepricee @TravisPearl MSR built Destination Maps as a Bing Map App. ^CP
-bingmaps: My IEEE article, "The World According to Bing" has gone syndicate. You can read it online now: http://bit.ly/apUnNL. ^CP
-bingmaps: @natelawrence You would think so...updates are coming, tho. The pump is certainly primed. ^CP
-bingmaps: RT @IncaX: IncaX, ONR, Pelican Racing and @BingMaps feature in GIS Professional magazine. http://tinyurl.com/34kjch7 ^CP
-bingmaps: @zafeuer Surprisingly, MQ is still number two in Map Search...for now. Do people still use AOL to connect to the intertube? ^CP
-bingmaps: @blakey15 Always a chance. Do you WANT a Silverlight experience or something within the SL experience?
-How up-to-date are the zip codes in MapPoint?
-MapPoint Business-Suite - freeware
 Resources
Browse GIS books and periodicals
Find a MapPoint Partner or Consultant
Real Estate Columbia, MO


Want Your Site To Appear Here?

   © 1999-2009 MP2K. Questions and comments to: website@mp2kmag.com
  Microsoft and MapPoint 2002/2004/2006/2009 are either trademarks or registered trademarks of Microsoft.

Improve your career with a computer degree LocalEDU.com
• Buy Toner Cartridges at Marquee Office Solutions
• Looking for Dry Erase Boards? See Dry Erase Boards • The Search Starts Here Used Cars
• 5339 - We Know Bikes: Road Bikes / Triathlon Bikes / Mountain Bikes / BMX Bikes
• Buy Your Car Used Cars UK, Car Lease and Contract Hire