<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Change layer's sqlWorkspace dynamically, datasource in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/change-layer-s-sqlworkspace-dynamically-datasource/m-p/531885#M14351</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi everyone&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I got query layers in a map document which point to sql server databases. I'm trying to find a way to change the database at which the query layer is pointing to. When assigning the new sqlWorkspace (with new connection properties) to an existing query layer an exception is raised saying "featureclass already exists". Some snippets of my code: &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
IWorkspace workspace = workspaceFactory.Open(connectionProps, 0);
ISqlWorkspace sqlWorkspace = (ISqlWorkspace)workspace;
IQueryDescription desc = sqlWorkspace.GetQueryDescription("select * from " + tblName);
ITable queryClass = sqlWorkspace.OpenQueryClass("MyQuery", desc);
IFeatureClass fc = (IFeatureClass)queryClass;
//assign the new fc to an existing map layer, this is where the exception happens
mapLayer.FeatureClass = fc;&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;how can i change the sql workspace of a map layer programmatically?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 07 Oct 2010 08:07:11 GMT</pubDate>
    <dc:creator>stefanschlaefli</dc:creator>
    <dc:date>2010-10-07T08:07:11Z</dc:date>
    <item>
      <title>Change layer's sqlWorkspace dynamically, datasource</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/change-layer-s-sqlworkspace-dynamically-datasource/m-p/531885#M14351</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi everyone&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I got query layers in a map document which point to sql server databases. I'm trying to find a way to change the database at which the query layer is pointing to. When assigning the new sqlWorkspace (with new connection properties) to an existing query layer an exception is raised saying "featureclass already exists". Some snippets of my code: &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
IWorkspace workspace = workspaceFactory.Open(connectionProps, 0);
ISqlWorkspace sqlWorkspace = (ISqlWorkspace)workspace;
IQueryDescription desc = sqlWorkspace.GetQueryDescription("select * from " + tblName);
ITable queryClass = sqlWorkspace.OpenQueryClass("MyQuery", desc);
IFeatureClass fc = (IFeatureClass)queryClass;
//assign the new fc to an existing map layer, this is where the exception happens
mapLayer.FeatureClass = fc;&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;how can i change the sql workspace of a map layer programmatically?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Oct 2010 08:07:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/change-layer-s-sqlworkspace-dynamically-datasource/m-p/531885#M14351</guid>
      <dc:creator>stefanschlaefli</dc:creator>
      <dc:date>2010-10-07T08:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: Change layer's sqlWorkspace dynamically, datasource</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/change-layer-s-sqlworkspace-dynamically-datasource/m-p/531886#M14352</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Stefan,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm not sure if this will help, but try making the first parameter of OpenQueryClass dynamic and unique, i.e. append a timestamp. As long as the layer object is still reused I don't think the change will be visible to the user.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;James&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Oct 2010 23:11:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/change-layer-s-sqlworkspace-dynamically-datasource/m-p/531886#M14352</guid>
      <dc:creator>JamesMacKay</dc:creator>
      <dc:date>2010-10-07T23:11:00Z</dc:date>
    </item>
    <item>
      <title>Re: Change layer's sqlWorkspace dynamically, datasource</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/change-layer-s-sqlworkspace-dynamically-datasource/m-p/531887#M14353</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi James&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for the hint, it works. And you're right, the user will not see it until the layer is refreshed (switch visibility on/off for example). Actually I try to use this in a ArcGIS server mapservice. The client shall be able to choose a db which is the datasource of a mapservice. I guess the code in this thread would be running in a server object extension. Do you know any other way to make mapservices (or maybe any other AGS service types) dynamic in a way that the client determines the datasource of the service?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Stefan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Oct 2010 07:38:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/change-layer-s-sqlworkspace-dynamically-datasource/m-p/531887#M14353</guid>
      <dc:creator>stefanschlaefli</dc:creator>
      <dc:date>2010-10-11T07:38:58Z</dc:date>
    </item>
  </channel>
</rss>

