Trying to create ITable from a MS SQL Server Express table with spatial column

1995
3
04-24-2012 04:28 PM
MartinWong
New Contributor II
Hi, I'm pretty new to C#, SQL Server, and AO so excuse the noobness.  What I want to do is take the AdventureWorks2012.Person.Address table (which contains the "SpatialLocation" geography column) stored in my local MS SQL Server Express server and create a query layer and eventually create an ILayer to display in a MapControl on a Windows form.  I've tried searching the forums but haven't had any luck finding anything.  Is there an example of this that someone can explain to me or point me to?

Thanks,
Martin
0 Kudos
3 Replies
MartinWong
New Contributor II
After doing more research I finally figured it out.

Esri has an exact example of what I was trying to accomplish here:
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//001p0000000t000000

My problem was that I've been trying to use a SqlWorkspaceFactory instead of an OLEDBWorkspaceFactory, plus I was missing the "@" character in my connection string.  Also, Esri's SqlWorkspaceFactory example was for a connection to an Oracle DB using a PropertySet so the connection parameters were very different.

Martin
0 Kudos
MartinWong
New Contributor II
I guess I spoke too soon.  Apparently the OLEDBWorkspaceFactory cannot be used to connect to spatial data.  But, I was finally able to use the SqlWorkspaceFactory once I got the connection parameters right:

  • dbclient = "SQLServer"

  • serverinstance = "MyPCName"

  • authentication_mode = "OSA"

  • database = "AdventureWorks2012"

After connecting and getting the SQLworkspace, I setup my queryDescription to the Person.Address table and used the OpenQueryClass method to create my feature class to add to the map control.

Martin
0 Kudos
DavidLednik
Occasional Contributor II
Hi Martin,

Is this SDE database?

David
0 Kudos